* {
  box-sizing: border-box;
}

:root {
  --track-gray: #666666;
  --yellow: #f6cc00;
  --white: #ffffff;
  --lane: #cc7d76;
  --infield: #b4d349;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-width: 0;
  min-height: 0;
  background: transparent;
  overscroll-behavior-x: none;
}

body {
  overflow-x: hidden;
  --footer-clearance: 72px;
  padding-bottom: calc(var(--footer-clearance) + 36px + env(safe-area-inset-bottom));
  scroll-padding-bottom: calc(var(--footer-clearance) + 36px + env(safe-area-inset-bottom));
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.rider-dragging {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

.controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.comment-input {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 680px;
  height: 42px;
  border: 1px solid #999;
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: #111;
  font: 400 16px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  outline: none;
}

.comment-input:focus {
  border-color: #555;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .08);
}

.bank-comment {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 20;
  max-width: 58%;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .82);
  color: #111;
  font: 700 clamp(14px, 2vw, 26px)/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
}

.save-duplicate {
  appearance: none;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 10px 18px;
  background: #fff;
  color: #111;
  font: 700 16px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}

.save-duplicate:active {
  transform: translateY(1px);
}

.bank-stack {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 0 calc(var(--footer-clearance) + 48px + env(safe-area-inset-bottom));
}

.track-figure {
  position: relative;
  width: calc(100% - 24px);
  margin-left: auto;
  margin-right: auto;
  aspect-ratio: 457 / 287;
  overflow: hidden;
  background: transparent;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: contain;
}

.track-outer,
.yellow-line,
.outer-white,
.race-lane,
.infield,
.marker,
.rider {
  position: absolute;
}

.track-outer {
  inset: 0;
  background: var(--track-gray);
  border-radius: 26.48% / 50%;
}

.yellow-line {
  left: 10.5033%;
  top: 13.9373%;
  width: 78.5558%;
  height: 72.1254%;
  border: clamp(1px, 0.22vw, 2px) solid var(--yellow);
  border-radius: 22.98% / 50%;
}

.outer-white {
  left: 14.2232%;
  top: 20.2091%;
  width: 70.8972%;
  height: 59.5819%;
  border: clamp(1px, 0.44vw, 3px) solid var(--white);
  border-radius: 23.15% / 50%;
}

.race-lane {
  left: 15.9737%;
  top: 22.6481%;
  width: 67.6149%;
  height: 54.7038%;
  background: var(--lane);
  border: clamp(1px, 0.44vw, 3px) solid var(--white);
  border-radius: 22.01% / 50%;
}

.infield {
  left: 18.3807%;
  top: 26.8293%;
  width: 62.5821%;
  height: 45.9930%;
  background: var(--infield);
  border-radius: 22.03% / 50%;
}

.marker {
  width: clamp(1px, 0.22vw, 2px);
  background: var(--white);
  z-index: 10;
}

.marker.top {
  left: 44.4201%;
  top: 0;
  height: 27.1777%;
}

.marker.bottom {
  top: 73.1707%;
  height: 26.8293%;
}

.marker.bottom.left   { left: 38.9497%; }
.marker.bottom.center { left: 55.3611%; }
.marker.bottom.right  { left: 69.1466%; }

.rider {
  z-index: 30;
  width: clamp(28px, 4.8vw, 56px);
  height: clamp(28px, 4.8vw, 56px);
  padding: 0;
  border: clamp(1px, 0.25vw, 2px) solid #333;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  font: 700 clamp(14px, 2.4vw, 28px)/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}

.rider:active,
.rider.dragging {
  cursor: grabbing;
  z-index: 50;
}

.track-figure.locked .rider {
  cursor: default;
  pointer-events: none;
}

.rider-1 { left: 13%;    top: 50%; background: #fff; }
.rider-2 { left: 22.25%; top: 50%; background: #050505; color: #fff; }
.rider-3 { left: 31.5%;  top: 50%; background: #ff514c; }
.rider-4 { left: 40.75%; top: 50%; background: #467bdc; }
.rider-5 { left: 50%;    top: 50%; background: #ffe34a; }
.rider-6 { left: 59.25%; top: 50%; background: #43ee4d; }
.rider-7 { left: 68.5%;  top: 50%; background: #ff922c; }
.rider-8 { left: 77.75%; top: 50%; background: #ff54a8; }
.rider-9 { left: 87%;    top: 50%; background: #a755e9; }

@media (max-width: 520px) {
  .controls {
    padding-left: 8px;
    padding-right: 8px;
  }

  .comment-input {
    height: 40px;
    font-size: 14px;
  }

  .save-duplicate {
    flex: 0 0 auto;
    padding: 10px 12px;
    font-size: 14px;
  }
}

/* ===== 買い目 ===== */
.footer-button {
  appearance: none;
  flex: 0 0 auto;
  height: 42px;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 0 16px;
  background: #fff;
  color: #111;
  font: 700 16px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}

.footer-button:active {
  transform: translateY(1px);
}

.bet-open {
  min-width: 72px;
}

.confirm-download {
  min-width: 72px;
  background: #111;
  color: #fff;
  border-color: #111;
}

.confirm-download:disabled {
  opacity: .65;
  cursor: wait;
}

.bet-summary {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 10px 12px 16px;
  background: #fff;
  border-bottom: 1px solid #ddd;
}

.bet-summary:empty {
  display: none;
}

.bet-summary-title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: #555;
}

.bet-summary-row,
.bet-modal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border-top: 1px solid #e5e5e5;
  font-size: 16px;
}

.bet-summary-row {
  width: 100%;
}

.bet-summary-row:last-child {
  border-bottom: 1px solid #e5e5e5;
}

.bet-summary:last-of-type {
  scroll-margin-bottom: calc(var(--footer-clearance) + 48px + env(safe-area-inset-bottom));
}

.bet-summary-text,
.bet-modal-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.bet-summary-text {
  width: 100%;
}

.bet-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
}

.bet-modal[hidden] {
  display: none;
}

.bet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .42);
}

.bet-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92vw, 430px);
  max-height: min(88vh, 720px);
  transform: translate(-50%, -50%);
  overflow: auto;
  padding: 14px;
  border-radius: 14px;
  background: #fff;
  color: #111;
  box-shadow: 0 14px 42px rgba(0, 0, 0, .28);
}

.bet-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.bet-panel-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #eee;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.bet-mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-left: 1px solid #d8d8d8;
  border-top: 1px solid #d8d8d8;
}

.bet-mode {
  min-height: 46px;
  border: 0;
  border-right: 1px solid #d8d8d8;
  border-bottom: 1px solid #d8d8d8;
  background: #fff;
  color: #111;
  font: 500 16px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 18px;
  justify-items: center;
  padding: 8px 10px 4px;
}

.number-pad .bet-number {
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid #333;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #111;
  font: 700 22px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.18);
}

.bet-number-1 { background: #fff; }
.bet-number-2 { background: #050505; color: #fff !important; }
.bet-number-3 { background: #ff514c; }
.bet-number-4 { background: #467bdc; }
.bet-number-5 { background: #ffe34a; }
.bet-number-6 { background: #43ee4d; }
.bet-number-7 { background: #ff922c; }
.bet-number-8 { background: #ff54a8; }
.bet-number-9 { background: #a755e9; }

.bet-mode.active {
  background: #111;
  color: #fff;
  font-weight: 700;
}

.number-pad .bet-number.selected {
  box-shadow: 0 0 0 4px #fff, 0 0 0 7px #111;
  transform: scale(1.04);
}

.bet-draft {
  padding: 10px 2px;
}

.bet-stage-label {
  margin-bottom: 4px;
  font-size: 12px;
  color: #666;
}

.bet-preview {
  min-height: 28px;
  font-size: 19px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.separator-controls {
  display: flex;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.separator-controls[hidden] {
  display: none;
}

.separator-field {
  display: grid;
  gap: 4px;
  flex: 0 0 auto;
}

.separator-field[hidden] {
  display: none;
}

.separator-field span {
  font-size: 12px;
  color: #666;
}

.separator-field select {
  min-width: 78px;
  height: 40px;
  border: 1px solid #999;
  border-radius: 8px;
  padding: 0 28px 0 12px;
  background: #fff;
  color: #111;
  font: 700 20px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.bet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  margin-top: 10px;
}

.bet-actions button,
.done-bet-modal,
.delete-bet {
  appearance: none;
  border: 1px solid #999;
  border-radius: 8px;
  background: #fff;
  color: #111;
  cursor: pointer;
  font: 700 14px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.bet-actions button {
  min-height: 40px;
  padding: 8px 10px;
}

.bet-actions .set-bet {
  border-color: #111;
  background: #111;
  color: #fff;
}

.bet-list-wrap {
  margin-top: 14px;
}

.bet-list-title {
  margin-bottom: 4px;
  font-size: 12px;
  color: #666;
}

.bet-modal-list {
  border-bottom: 1px solid #e5e5e5;
}

.bet-modal-row {
  padding: 4px 0;
}

.delete-bet {
  flex: 0 0 auto;
  min-width: 54px;
  min-height: 30px;
  padding: 4px 8px;
  border-color: #c5c5c5;
  color: #b40000;
}

.empty-bet-list {
  padding: 10px 0;
  color: #888;
  font-size: 14px;
}

.done-bet-modal {
  width: 100%;
  min-height: 42px;
  margin-top: 14px;
  border-color: #444;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 640px) {
  .controls {
    gap: 6px;
  }

  .comment-input {
    max-width: none;
  }

  .footer-button {
    height: 40px;
    padding: 0 10px;
    font-size: 13px;
  }

  .bet-open {
    min-width: 58px;
  }
}

/* ===== バンク下の買い目表示 ===== */
.bet-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.bet-summary-header .bet-summary-title {
  margin: 0;
}

.bet-summary-total {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 800;
  color: #111;
}

.bet-display {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  line-height: 1.4;
}

.bet-chip {
  display: inline-grid;
  place-items: center;
  text-align: center;
  text-indent: 0;
  width: 28px;
  height: 28px;
  border: 1.5px solid #333;
  border-radius: 50%;
  color: #111;
  font: 700 15px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  box-shadow: 0 1px 1px rgba(0,0,0,.12);
}

.bet-chip-1 { background: #fff; }
.bet-chip-2 { background: #050505; color: #fff; }
.bet-chip-3 { background: #ff514c; }
.bet-chip-4 { background: #467bdc; }
.bet-chip-5 { background: #ffe34a; }
.bet-chip-6 { background: #43ee4d; }
.bet-chip-7 { background: #ff922c; }
.bet-chip-8 { background: #ff54a8; }
.bet-chip-9 { background: #a755e9; }

.bet-separator {
  display: inline-block;
  padding: 0 1px;
  font-size: 20px;
  font-weight: 700;
  color: #111;
}

.bet-box-label {
  margin-right: 2px;
  font-size: 15px;
  font-weight: 700;
}

@media (max-width: 520px) {
  .bet-summary {
    padding-left: 8px;
    padding-right: 8px;
  }

  .bet-summary-total {
    font-size: 14px;
  }

  .bet-chip {
    width: 25px;
    height: 25px;
    font-size: 13px;
  }

  .bet-separator {
    font-size: 18px;
  }
}

/* ===== UI theme v2 ===== */
:root {
  --ui-bg: #0b0f14;
  --ui-surface: #121821;
  --ui-surface-2: #19212c;
  --ui-line: rgba(255, 255, 255, .10);
  --ui-text: #f6f8fb;
  --ui-muted: #8e9aab;
  --ui-yellow: #ffd43b;
  --ui-blue: #26a8ff;
  --ui-green: #30d17d;
}

html,
body {
  background: var(--ui-bg);
  color: var(--ui-text);
}

body {
  min-height: 100vh;
}

.app-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 66px;
  padding: 12px clamp(14px, 3vw, 34px);
  background:
    radial-gradient(circle at 12% 0%, rgba(38,168,255,.16), transparent 32%),
    linear-gradient(135deg, #111822 0%, #0b0f14 72%);
  border-bottom: 1px solid rgba(255,255,255,.09);
}

.app-brand {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.app-brand strong {
  font-size: clamp(17px, 2.2vw, 27px);
  line-height: 1;
  letter-spacing: .06em;
  color: #fff;
  white-space: nowrap;
}

.app-kicker {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .26em;
  color: var(--ui-yellow);
}

.app-subtitle {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 999px;
  background: rgba(255,255,255,.04);
  color: #aeb8c6;
  font-size: 12px;
  font-weight: 700;
}

.bank-stack {
  background: #090c10;
}

.track-figure {
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.track-figure.active {
  outline: 1px solid rgba(255,212,59,.18);
  outline-offset: -1px;
}

.rider {
  border-color: rgba(10,12,15,.86);
  box-shadow: 0 3px 10px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.12) inset;
  transition: transform .12s ease, box-shadow .12s ease;
}

.rider:hover:not(.dragging) {
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 5px 16px rgba(0,0,0,.45), 0 0 0 2px rgba(255,255,255,.35);
}

.rider.dragging {
  transform: translate(-50%, -50%) scale(1.12);
  box-shadow: 0 8px 20px rgba(0,0,0,.50), 0 0 0 3px var(--ui-yellow);
}

.bank-comment {
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 10px;
  background: rgba(7,11,16,.82);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.bet-summary {
  padding: 14px clamp(12px, 2.6vw, 28px) 18px;
  background: linear-gradient(180deg, #151c25 0%, #10161e 100%);
  color: var(--ui-text);
  border-top: 1px solid rgba(255,255,255,.06);
  border-bottom: 1px solid rgba(255,255,255,.10);
}

.bet-summary-header {
  min-height: 34px;
  margin-bottom: 8px;
}

.bet-summary-header .bet-summary-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #fff;
  font-size: 14px;
  letter-spacing: .08em;
}

.bet-summary-header .bet-summary-title::before {
  content: "";
  width: 4px;
  height: 16px;
  border-radius: 99px;
  background: var(--ui-blue);
  box-shadow: 0 0 12px rgba(38,168,255,.55);
}

.bet-summary-total {
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255,212,59,.10);
  border: 1px solid rgba(255,212,59,.25);
  color: var(--ui-yellow);
  font-size: 14px;
}

.bet-summary-row {
  min-height: 42px;
  padding: 5px 0;
  border-top-color: rgba(255,255,255,.08);
}

.bet-summary-row:last-child {
  border-bottom-color: rgba(255,255,255,.08);
}

.bet-separator,
.bet-box-label {
  color: #d9e0e8;
}

.bet-chip {
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto auto;
  gap: 8px;
  padding: 10px clamp(10px, 2vw, 20px) calc(10px + env(safe-area-inset-bottom));
  background: rgba(12,17,23,.92);
  border-top: 1px solid rgba(255,255,255,.11);
  box-shadow: 0 -12px 30px rgba(0,0,0,.26);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

.comment-input {
  width: 100%;
  max-width: none;
  height: 46px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 11px;
  padding: 0 14px;
  background: #171e28;
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset;
}

.comment-input::placeholder {
  color: #768294;
}

.comment-input:focus {
  border-color: rgba(38,168,255,.75);
  box-shadow: 0 0 0 3px rgba(38,168,255,.14);
}

.footer-button,
.save-duplicate {
  height: 46px;
  border-radius: 11px;
  border: 1px solid rgba(255,255,255,.12);
  padding: 0 16px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}

.footer-button:hover,
.save-duplicate:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 16px rgba(0,0,0,.24);
}

.save-duplicate {
  background: linear-gradient(180deg, #ffc94a, #eba900);
  border-color: #ffd76d;
  color: #15100a;
}

.bet-open {
  background: linear-gradient(180deg, #2d9de3, #1476b7);
  border-color: #46b5f9;
}

.confirm-download {
  background: linear-gradient(180deg, #35d88a, #159757);
  border-color: #53e7a0;
  color: #07140d;
}

.confirm-download:disabled {
  filter: saturate(.4);
}

.bet-backdrop {
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.bet-panel {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 16px;
  background:
    radial-gradient(circle at 100% 0%, rgba(38,168,255,.12), transparent 34%),
    #121821;
  color: var(--ui-text);
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}

.bet-panel-header {
  margin-bottom: 12px;
}

.bet-panel-header h2 {
  font-size: 19px;
  letter-spacing: .08em;
}

.modal-close {
  background: #202a36;
  color: #dfe6ef;
  border: 1px solid rgba(255,255,255,.08);
}

.bet-mode-grid {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 10px;
  background: #0d1218;
}

.bet-mode {
  border: 0;
  border-right: 1px solid rgba(255,255,255,.08);
  background: transparent;
  color: #98a5b5;
}

.bet-mode:last-child {
  border-right: 0;
}

.bet-mode.active {
  background: linear-gradient(180deg, #2d9de3, #1476b7);
  color: #fff;
}

.bet-draft {
  margin: 12px 0 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  background: #0d1218;
}

.bet-stage-label,
.separator-field span,
.bet-list-title {
  color: var(--ui-muted);
}

.bet-preview {
  color: #fff;
}

.number-pad {
  padding-top: 12px;
  padding-bottom: 10px;
}

.number-pad .bet-number {
  border-color: rgba(0,0,0,.75);
  box-shadow: 0 5px 12px rgba(0,0,0,.30), 0 0 0 1px rgba(255,255,255,.10) inset;
  transition: transform .1s ease, box-shadow .1s ease;
}

.number-pad .bet-number:hover {
  transform: translateY(-1px) scale(1.04);
}

.number-pad .bet-number.selected {
  box-shadow: 0 0 0 3px #121821, 0 0 0 6px var(--ui-yellow), 0 7px 16px rgba(0,0,0,.32);
}

.separator-field select {
  border-color: rgba(255,255,255,.13);
  background: #1a2330;
  color: #fff;
}

.bet-actions button,
.done-bet-modal,
.delete-bet {
  border-color: rgba(255,255,255,.12);
  background: #1b2430;
  color: #dce4ed;
}

.bet-actions .set-bet {
  border-color: #46b5f9;
  background: linear-gradient(180deg, #2d9de3, #1476b7);
  color: #fff;
}

.bet-modal-list {
  border-bottom-color: rgba(255,255,255,.08);
}

.bet-modal-row {
  border-top-color: rgba(255,255,255,.08);
}

.delete-bet {
  color: #ff7c7c;
}

.empty-bet-list {
  color: #768294;
}

.done-bet-modal {
  background: #202a36;
}

@media (max-width: 720px) {
  .app-header {
    min-height: 56px;
    padding: 10px 12px;
  }

  .app-subtitle {
    display: none;
  }

  .app-brand strong {
    font-size: 17px;
  }

  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .comment-input {
    grid-column: 1 / -1;
    height: 42px;
  }

  .footer-button,
  .save-duplicate {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 0 8px;
    font-size: 12px;
  }
}


/* ===== Race metadata ===== */
.race-meta {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(170px, .85fr) minmax(230px, 1.35fr) minmax(110px, .45fr);
  gap: 10px;
  width: 100%;
  padding: 10px clamp(12px, 2.5vw, 28px) 12px;
  background: linear-gradient(180deg, #0f151d 0%, #0c1117 100%);
  border-bottom: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 8px 20px rgba(0,0,0,.14);
}

.race-meta-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.race-meta-field > span {
  color: #8290a3;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  white-space: nowrap;
}

.race-meta input,
.race-meta select {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px;
  outline: none;
  background: #171e28;
  color: #f5f8fc;
  font: 700 14px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  box-shadow: 0 1px 0 rgba(255,255,255,.035) inset;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.race-meta input {
  padding: 0 11px;
}

.race-meta select {
  padding: 0 34px 0 11px;
  cursor: pointer;
}

.race-meta input:focus,
.race-meta select:focus {
  border-color: rgba(38,168,255,.72);
  background: #1a2330;
  box-shadow: 0 0 0 3px rgba(38,168,255,.12);
}

.race-meta input[type="date"] {
  color-scheme: dark;
}

.race-number-wrap {
  position: relative;
  min-width: 0;
}

.race-number-wrap input {
  padding-right: 34px;
  appearance: textfield;
  -moz-appearance: textfield;
}

.race-number-wrap input::-webkit-inner-spin-button,
.race-number-wrap input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.race-number-wrap b {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ui-yellow);
  font-size: 13px;
  pointer-events: none;
}

@media (max-width: 720px) {
  .race-meta {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) 88px;
    gap: 7px;
    padding: 8px;
  }

  .race-meta-field {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .race-meta-field > span {
    font-size: 10px;
  }

  .race-meta input,
  .race-meta select {
    height: 38px;
    font-size: 13px;
  }
}

@media (max-width: 440px) {
  .race-meta {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
  }

  .race-meta-field {
    min-width: 0;
    overflow: hidden;
  }

  .race-meta input,
  .race-meta select,
  .race-number-wrap,
  .race-number-wrap input {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .race-meta input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
    padding-left: 8px;
    padding-right: 8px;
    text-align: center;
    font-size: 16px;
  }

  .race-meta select {
    font-size: 16px;
  }

  .race-field {
    grid-column: 1 / -1;
  }
}


/* ===== iPhone Safari fixes ===== */
.comment-input {
  font-size: 16px;
}

.race-meta input[type="date"] {
  display: block;
  min-height: 40px;
  line-height: 40px;
  padding-top: 0;
  padding-bottom: 0;
  vertical-align: middle;
  -webkit-appearance: none;
  appearance: none;
}

.race-meta input[type="date"]::-webkit-date-and-time-value {
  min-height: 40px;
  line-height: 40px;
  padding: 0;
  margin: 0;
  text-align: center;
}

.race-meta input[type="date"]::-webkit-datetime-edit {
  display: flex;
  align-items: center;
  min-height: 40px;
  line-height: 40px;
  padding: 0;
}

.race-meta input[type="date"]::-webkit-datetime-edit-fields-wrapper {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0;
}

@media (max-width: 720px) {
  /* 16px未満だとiOS Safariがフォーカス時に自動ズームするため固定 */
  .comment-input,
  .race-meta input,
  .race-meta select {
    font-size: 16px;
  }

  .race-meta input[type="date"] {
    min-height: 38px;
    line-height: 38px;
  }

  .race-meta input[type="date"]::-webkit-date-and-time-value,
  .race-meta input[type="date"]::-webkit-datetime-edit {
    min-height: 38px;
    line-height: 38px;
  }
}

/* ===== Race participants controls ===== */
.race-meta {
  grid-template-columns: minmax(170px, .75fr) minmax(230px, 1.25fr) minmax(320px, 1.15fr);
}

.race-entry-row {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) 86px auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.race-number-wrap,
.vehicle-count-wrap {
  position: relative;
  display: block;
  min-width: 0;
}

.vehicle-count-wrap select {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 30px 0 10px;
}

.vehicle-count-wrap b {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ui-yellow);
  font-size: 13px;
  pointer-events: none;
}

.pacer-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-width: 0;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px;
  background: #171e28;
  color: #f5f8fc;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.pacer-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 0;
  accent-color: #22d3ee;
}

.pacer-toggle span {
  color: #f5f8fc;
  letter-spacing: 0;
}

.pacer-marker {
  left: 50%;
  top: 35%;
  background: #22d3ee;
  color: #06242a;
  border-color: #0b3f48;
  box-shadow: 0 0 0 2px rgba(255,255,255,.25), 0 2px 8px rgba(34,211,238,.4);
}

.pacer-marker[hidden],
.rider[hidden],
.bet-number[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .race-meta {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  }

  .race-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .race-meta {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .race-field {
    grid-column: 1 / -1;
  }

  .race-entry-row {
    grid-template-columns: minmax(92px, 1fr) 86px auto;
  }

  .vehicle-count-wrap select,
  .pacer-toggle {
    height: 38px;
    min-height: 38px;
    font-size: 13px;
  }
}

@media (max-width: 440px) {
  .race-entry-row {
    grid-template-columns: minmax(0, 1fr) 78px auto;
    gap: 6px;
  }

  .vehicle-count-wrap,
  .vehicle-count-wrap select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .pacer-toggle {
    padding: 0 6px;
    font-size: 12px;
  }

  .pacer-toggle input[type="checkbox"] {
    width: 17px;
    height: 17px;
    min-width: 17px;
  }
}


/* 車数はプルダウンの外側に「車」を表示 */
.vehicle-count-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}

.vehicle-count-wrap select {
  flex: 1 1 auto;
  width: auto;
  min-width: 52px;
  padding-right: 26px;
}

.vehicle-count-wrap b {
  position: static;
  right: auto;
  top: auto;
  transform: none;
  flex: 0 0 auto;
}

@media (max-width: 720px) {
  .vehicle-count-wrap select,
  .pacer-toggle {
    font-size: 16px;
  }
}

/* 車数は最初の複製後に固定 */
.vehicle-count-wrap select:disabled {
  opacity: 1;
  color: #f5f8fc;
  -webkit-text-fill-color: #f5f8fc;
  cursor: not-allowed;
  background: #121923;
  border-color: rgba(255,255,255,.08);
}

/* ===== iPhone Safari: 車数プルダウンの数値を確実に表示 ===== */
.vehicle-count-wrap {
  position: relative;
  flex: 0 0 auto;
  min-width: 92px;
}

.vehicle-count-wrap select {
  flex: 0 0 62px;
  width: 62px;
  min-width: 62px;
  max-width: 62px;
  padding: 0 20px 0 8px;
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
  text-align-last: center;
  font-variant-numeric: tabular-nums;
}

.vehicle-count-wrap::after {
  content: "▼";
  position: absolute;
  left: 43px;
  top: 50%;
  transform: translateY(-50%) scale(.72);
  color: #8290a3;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}

.vehicle-count-wrap select:disabled + b ~ * {
  pointer-events: none;
}

.vehicle-count-wrap:has(select:disabled)::after {
  opacity: .45;
}

@media (max-width: 440px) {
  .race-entry-row {
    grid-template-columns: minmax(0, 1fr) 92px 112px;
    gap: 7px;
  }

  .vehicle-count-wrap {
    min-width: 92px;
    width: 92px;
  }

  .vehicle-count-wrap select {
    flex-basis: 62px;
    width: 62px;
    min-width: 62px;
    max-width: 62px;
    padding-left: 8px;
    padding-right: 20px;
  }

  .pacer-toggle {
    width: 112px;
    min-width: 112px;
    justify-content: center;
  }
}


/* ===== Auto save / restore ===== */
.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.new-simulation {
  appearance: none;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 9px;
  background: rgba(255,255,255,.06);
  color: #dbe3ee;
  font: 800 12px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
}

.new-simulation:active {
  transform: translateY(1px);
  background: rgba(255,255,255,.10);
}

.restore-toast {
  position: fixed;
  left: 50%;
  top: calc(74px + env(safe-area-inset-top));
  z-index: 5000;
  transform: translateX(-50%);
  max-width: calc(100vw - 28px);
  padding: 10px 14px;
  border: 1px solid rgba(48,209,125,.38);
  border-radius: 999px;
  background: rgba(13, 28, 24, .96);
  color: #c9ffe2;
  box-shadow: 0 10px 30px rgba(0,0,0,.28);
  font: 800 13px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  white-space: nowrap;
  pointer-events: none;
  opacity: 1;
  transition: opacity .25s ease, transform .25s ease;
}

.restore-toast.is-hiding {
  opacity: 0;
  transform: translate(-50%, -6px);
}

@media (max-width: 720px) {
  .app-header-actions {
    margin-left: auto;
  }

  .new-simulation {
    min-height: 32px;
    padding: 0 10px;
    font-size: 11px;
  }

  .restore-toast {
    top: calc(62px + env(safe-area-inset-top));
    font-size: 12px;
  }
}


/* ===== Free text comment / bet markers ===== */
.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
}

.footer-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.footer-field > span {
  padding-left: 2px;
  color: #93a2b7;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
}

.comment-input,
.bet-free-input {
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 42px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  padding: 0 12px;
  background: #171e28;
  color: #f5f8fc;
  font-size: 16px;
  line-height: 1.2;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.035);
}

.comment-input:focus,
.bet-free-input:focus {
  border-color: rgba(38,168,255,.72);
  background: #1a2330;
  box-shadow: 0 0 0 3px rgba(38,168,255,.12);
}

.rider.text-marker {
  width: auto;
  max-width: 58%;
  height: auto;
  min-height: clamp(28px, 4vw, 42px);
  padding: clamp(4px, .8vw, 8px) clamp(8px, 1.4vw, 14px);
  border-radius: 999px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(11px, 1.8vw, 20px);
  font-weight: 800;
  line-height: 1.15;
  color: #fff;
  text-align: left;
  letter-spacing: .01em;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
}

.rider.comment-marker {
  left: 28%;
  top: 34%;
  background: rgba(79,70,229,.94);
  border-color: #a5b4fc;
}

.rider.bet-text-marker {
  left: 72%;
  top: 66%;
  background: rgba(146,64,14,.95);
  border-color: #fbbf24;
}

.rider.text-marker.dragging {
  box-shadow: 0 8px 24px rgba(0,0,0,.42), 0 0 0 3px rgba(255,255,255,.32);
}

.track-figure.locked .text-marker {
  cursor: default;
}

@media (max-width: 720px) {
  .controls {
    grid-template-columns: 1fr 1fr;
    align-items: end;
  }
  .footer-field {
    grid-column: 1 / -1;
  }
  .save-duplicate,
  .confirm-download {
    width: 100%;
  }
  .rider.text-marker {
    max-width: 68%;
    font-size: clamp(11px, 3.2vw, 16px);
  }
}


/* ===== Multiline notes ===== */
.comment-input,
.bet-free-input {
  min-height: 58px;
  height: 58px;
  padding: 8px 12px;
  resize: vertical;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-y: auto;
  font-size: 16px;
}

.bank-comment-note {
  display: block;
  width: 100%;
  margin: 0;
  padding: 10px clamp(12px, 2.5vw, 28px) 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(180deg, #151c26 0%, #111822 100%);
  color: #eef4fb;
  font: 700 clamp(13px, 1.7vw, 18px)/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bank-comment-note::before {
  content: "COMMENT";
  display: block;
  margin-bottom: 4px;
  color: #8290a3;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: .12em;
}

.rider.comment-marker {
  display: none !important;
}

.rider.bet-text-marker {
  white-space: pre-wrap;
  overflow: visible;
  text-overflow: clip;
  max-width: 72%;
  border-radius: 12px;
  line-height: 1.3;
}

@media (max-width: 720px) {
  .comment-input,
  .bet-free-input {
    min-height: 64px;
    height: 64px;
    font-size: 16px;
  }

  .rider.bet-text-marker {
    max-width: 78%;
  }
}


/* ===== Fixed comment / bet notes ===== */
.bank-bet-note {
  display: block;
  width: 100%;
  margin: 0;
  padding: 10px clamp(12px, 2.5vw, 28px) 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(180deg, #171b21 0%, #12171e 100%);
  color: #fff4d6;
  font: 700 clamp(13px, 1.7vw, 18px)/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bank-bet-note::before {
  content: "BET";
  display: block;
  margin-bottom: 4px;
  color: #d9a441;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: .12em;
}

.rider.bet-text-marker {
  display: none !important;
}


/* ===== Restricted bet keyboard ===== */
.bet-free-input[readonly] {
  cursor: pointer;
  caret-color: #f6cc00;
  user-select: text;
  -webkit-user-select: text;
}

.bet-entry-field {
  position: relative;
}

.bet-keyboard {
  display: grid;
  gap: 8px;
  width: 100%;
  margin-top: 2px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 12px;
  background: #0f151d;
  box-shadow: 0 -8px 28px rgba(0,0,0,.28);
}

.bet-keyboard[hidden] {
  display: none !important;
}

.bet-keyboard-numbers {
  display: grid;
  grid-template-columns: repeat(9, minmax(30px, 1fr));
  gap: 6px;
}

.bet-keyboard-ops {
  display: grid;
  grid-template-columns: repeat(7, minmax(48px, 1fr));
  gap: 6px;
}

.bet-key {
  min-width: 0;
  height: 38px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 9px;
  font: 800 14px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 1px 2px rgba(0,0,0,.24);
}

.bet-key-number {
  border-radius: 50%;
  width: 38px;
  max-width: 38px;
  justify-self: center;
}

.bet-key-op,
.bet-key-close {
  background: #1b2531;
  color: #f4f7fb;
}

.bet-key-box {
  color: #ffd24d;
}

.bet-key-close {
  border-color: rgba(38,168,255,.45);
  color: #63c5ff;
}

.bet-key:active {
  transform: translateY(1px) scale(.98);
}

.bet-key:disabled,
.bet-key[hidden] {
  opacity: .22;
  cursor: default;
}

/* 買い目表示：数字はバンク上と同じ色付き車番マーカー */
.bank-bet-note {
  line-height: 1.9;
}

.bank-bet-note-content {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
}

.bank-bet-note .bet-chip {
  display: inline-grid;
  place-items: center;
  text-align: center;
  text-indent: 0;
  width: clamp(25px, 3vw, 34px);
  height: clamp(25px, 3vw, 34px);
  margin: 1px 2px;
  padding: 0;
  border: 1px solid #333;
  border-radius: 50%;
  color: #111;
  font: 800 clamp(12px, 1.6vw, 17px)/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  vertical-align: middle;
  box-shadow: 0 1px 2px rgba(0,0,0,.22);
}

.bank-bet-note .bet-chip-2 { color: #fff; }

.bank-bet-note .bet-token {
  display: inline-block;
  margin: 0 2px;
  color: #fff4d6;
  font-weight: 900;
  vertical-align: middle;
}

.bank-bet-note .bet-token-box {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(217,164,65,.16);
  color: #ffd26a;
  letter-spacing: .04em;
}

@media (max-width: 720px) {
  .bet-keyboard-numbers {
    grid-template-columns: repeat(5, 1fr);
  }
  .bet-keyboard-ops {
    grid-template-columns: repeat(4, 1fr);
  }
  .bet-key-number {
    width: 40px;
    max-width: 40px;
    height: 40px;
  }
  .bet-key {
    font-size: 15px;
  }
}


/* ===== Existing bank editing / deletion ===== */
.bank-action-buttons {
  position: absolute;
  right: clamp(8px, 1.6vw, 18px);
  top: clamp(8px, 1.6vw, 18px);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bank-action-buttons[hidden] {
  display: none !important;
}

.bank-edit-button,
.bank-delete-button {
  position: static;
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  color: #fff;
  font: 800 clamp(11px, 1.5vw, 14px)/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  box-shadow: 0 5px 16px rgba(0,0,0,.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}

.bank-edit-button {
  background: rgba(10, 16, 24, .82);
}

.bank-delete-button {
  border-color: rgba(255, 102, 102, .50);
  background: rgba(116, 24, 28, .90);
  color: #ffe7e7;
}

.bank-edit-button:active,
.bank-delete-button:active {
  transform: translateY(1px);
}

.track-figure.editing-existing {
  outline: 3px solid rgba(255, 204, 0, .92);
  outline-offset: -3px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.16);
}

.track-figure.editing-existing::after {
  content: "編集中";
  position: absolute;
  top: clamp(8px, 1.6vw, 18px);
  right: clamp(8px, 1.6vw, 18px);
  z-index: 82;
  padding: 7px 12px;
  border-radius: 999px;
  background: #f6cc00;
  color: #111;
  font: 900 clamp(11px, 1.5vw, 14px)/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  pointer-events: none;
}

.edit-save {
  background: linear-gradient(180deg, #ffd54a 0%, #ffb800 100%);
  border-color: #ffd34a;
  color: #101318;
}

.edit-cancel {
  background: #28313e;
  border-color: rgba(255,255,255,.18);
  color: #f3f6fa;
}

.controls.editing-existing-mode {
  border-top-color: rgba(246,204,0,.38);
  box-shadow: 0 -8px 28px rgba(0,0,0,.34), 0 -1px 0 rgba(246,204,0,.18);
}

@media (max-width: 720px) {
  .controls.editing-existing-mode {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .controls.editing-existing-mode .footer-field {
    grid-column: 1 / -1;
  }

  .controls.editing-existing-mode .edit-save,
  .controls.editing-existing-mode .edit-cancel,
  .controls.editing-existing-mode .confirm-download {
    width: 100%;
    padding-left: 8px;
    padding-right: 8px;
    font-size: 13px;
  }
}

/* ===== Scroll gutters around banks ===== */
@media (max-width: 520px) {
  .track-figure {
    width: calc(100% - 20px);
  }
}


/* ===== PWA ===== */
.install-app {
  appearance: none;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(38,168,255,.40);
  border-radius: 9px;
  background: rgba(38,168,255,.12);
  color: #bfe7ff;
  font: 800 12px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
}

.install-app:active {
  transform: translateY(1px);
  background: rgba(38,168,255,.20);
}

.install-app[hidden] {
  display: none !important;
}

.install-modal {
  position: fixed;
  inset: 0;
  z-index: 6000;
}

.install-modal[hidden] {
  display: none;
}

.install-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.62);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.install-panel {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(calc(100vw - 24px), 460px);
  transform: translateX(-50%);
  padding: 18px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  background: linear-gradient(180deg, #171f2a 0%, #10161e 100%);
  color: #f6f8fb;
  box-shadow: 0 24px 70px rgba(0,0,0,.48);
}

.install-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 14px;
}

.install-kicker {
  color: var(--ui-blue);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .18em;
}

.install-panel h2 {
  margin: 3px 0 0;
  font-size: 21px;
}

.install-modal-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
}

.install-steps {
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: rgba(255,255,255,.04);
}

.install-steps[hidden] {
  display: none;
}

.install-steps p {
  margin: 0 0 8px;
}

.install-steps ol {
  margin: 0;
  padding-left: 1.4em;
}

.install-steps li + li {
  margin-top: 7px;
}

.install-note {
  margin: 12px 2px 0;
  color: #9dabbd;
  font-size: 12px;
  line-height: 1.6;
}

.install-modal-done {
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  border: 1px solid rgba(38,168,255,.55);
  border-radius: 10px;
  background: linear-gradient(180deg, #30b6ff 0%, #168bc9 100%);
  color: #fff;
  font: 900 14px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
}

@media (max-width: 720px) {
  .install-app,
  .new-simulation {
    min-height: 32px;
    padding: 0 9px;
    font-size: 10.5px;
  }

  .app-header-actions {
    gap: 6px;
  }

  .app-subtitle {
    display: none;
  }
}

@media (display-mode: standalone) {
  .install-app {
    display: none !important;
  }
}


/* ===== Utility navigation ===== */
.utility-nav {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px clamp(12px, 2.5vw, 28px);
  background: #0c1117;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.utility-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 999px;
  background: rgba(255,255,255,.04);
  color: #cbd5e1;
  font: 800 11px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-decoration: none;
}
.utility-nav a:active {
  background: rgba(38,168,255,.16);
  border-color: rgba(38,168,255,.35);
}
@media (max-width: 520px) {
  .utility-nav { justify-content: flex-start; padding: 5px 10px; }
  .utility-nav a { min-height: 28px; font-size: 11px; }
}
