:root {
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1b202b;
  --surface-3: #252c39;
  --text: #f4f6fa;
  --muted: #9ba5b5;
  --line: #2c3442;
  --accent: #45d39c;
  --accent-strong: #21b982;
  --accent-ink: #07140f;
  --danger: #ff6b74;
  --warning: #ffca5c;
  --blue: #72a7ff;
  --red-suit: #ff6b74;
  --black-suit: #e9edf5;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; }
button { border: 0; }
button, [role="button"] { touch-action: manipulation; }
input, select, textarea { color-scheme: dark; }

#app { min-height: 100dvh; }

.app-shell {
  min-height: 100dvh;
  padding: calc(10px + var(--safe-top)) 14px calc(92px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.app-shell.no-nav { padding-bottom: calc(102px + var(--safe-bottom)); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  gap: 10px;
  margin-bottom: 10px;
}

.topbar-title { min-width: 0; }
.topbar h1 { font-size: 19px; line-height: 1.2; margin: 0; letter-spacing: -0.02em; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn, .back-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 20px;
  flex: 0 0 auto;
}
.icon-btn:active, .back-btn:active { transform: scale(0.97); background: var(--surface-3); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card.flat { box-shadow: none; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
}
.section-title h2, .section-title h3 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }
.section-title .subtle { font-size: 12px; color: var(--muted); }

.clock-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #17221f 0%, #111820 58%, #131722 100%);
}
.clock-card::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -84px;
  top: -106px;
  border-radius: 50%;
  background: rgba(69, 211, 156, 0.08);
}
.clock-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; position: relative; z-index: 1; }
.clock-kicker { color: var(--accent); font-weight: 700; font-size: 13px; }
.clock-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.blind-line { font-size: clamp(27px, 8vw, 38px); line-height: 1; font-weight: 800; margin: 12px 0 6px; letter-spacing: -0.035em; position: relative; z-index: 1; }
.blind-line.break { color: var(--warning); }
.level-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; position: relative; z-index: 1; }
.countdown { margin-left: auto; color: var(--text); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.progress { height: 6px; border-radius: 999px; overflow: hidden; background: #242b36; margin-top: 12px; position: relative; z-index: 1; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.4s linear; }
.clock-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; position: relative; z-index: 1; }

.btn {
  min-height: 46px;
  border-radius: 14px;
  padding: 10px 14px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  border: 1px solid var(--line);
}
.btn:active { transform: scale(0.985); background: var(--surface-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:active { background: var(--accent-strong); }
.btn.danger { background: rgba(255, 107, 116, 0.12); color: var(--danger); border-color: rgba(255, 107, 116, 0.34); }
.btn.warning { background: rgba(255, 202, 92, 0.12); color: var(--warning); border-color: rgba(255, 202, 92, 0.34); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.small { min-height: 38px; padding: 7px 11px; border-radius: 11px; font-size: 13px; }
.btn:disabled { opacity: 0.42; pointer-events: none; }

.record-btn {
  width: 100%;
  min-height: 88px;
  margin-top: 12px;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 850;
  font-size: 22px;
  letter-spacing: -0.02em;
  box-shadow: 0 16px 36px rgba(33, 185, 130, 0.2);
}
.record-btn span { display: block; font-size: 12px; font-weight: 700; opacity: 0.72; margin-top: 4px; }
.record-btn:active { transform: scale(0.987); background: var(--accent-strong); }

.stack-card { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.stack-value { font-size: 30px; font-weight: 850; letter-spacing: -0.04em; }
.stack-value small { font-size: 14px; color: var(--muted); letter-spacing: 0; }
.stack-controls { display: grid; grid-template-columns: repeat(4, 44px); gap: 6px; }
.stack-controls button { height: 44px; border-radius: 12px; background: var(--surface-2); color: var(--text); font-weight: 800; }
.stack-controls button:active { background: var(--surface-3); transform: scale(0.96); }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 7px 10px calc(7px + var(--safe-bottom));
  background: rgba(11, 13, 18, 0.92);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-top: 1px solid rgba(255,255,255,0.08);
  z-index: 20;
}
.bottom-nav-inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.nav-btn { min-height: 54px; border-radius: 13px; background: transparent; color: var(--muted); display: grid; place-items: center; gap: 1px; font-size: 11px; }
.nav-btn .nav-icon { font-size: 20px; line-height: 1; }
.nav-btn.active { color: var(--accent); background: rgba(69, 211, 156, 0.08); }

.empty-state { text-align: center; padding: 40px 18px; }
.empty-icon { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 24px; background: rgba(69,211,156,0.1); color: var(--accent); font-size: 38px; margin: 0 auto 16px; }
.empty-state h2 { margin: 0 0 8px; font-size: 21px; }
.empty-state p { margin: 0 auto 18px; color: var(--muted); line-height: 1.7; max-width: 380px; font-size: 14px; }

.choice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choice-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.choice-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.choice-grid.auto { grid-template-columns: repeat(auto-fit, minmax(74px, 1fr)); }
.choice-btn {
  min-height: 48px;
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 750;
  padding: 8px 5px;
}
.choice-btn:active { transform: scale(0.97); background: var(--surface-3); }
.choice-btn.selected { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.choice-btn.selected.alt { background: var(--blue); color: #07101e; }
.choice-btn.danger-selected { background: var(--danger); color: #1b0709; border-color: transparent; }

.form-section { margin-top: 16px; }
.form-label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 800; margin-bottom: 8px; }
.form-help { font-size: 11px; font-weight: 500; color: var(--muted); }

.card-slots { display: flex; justify-content: center; gap: 12px; margin: 8px 0 13px; }
.playing-card {
  width: 72px;
  height: 94px;
  border-radius: 13px;
  background: #f7f8fa;
  color: #151821;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  border: 3px solid transparent;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.playing-card.red { color: #d72f3c; }
.playing-card.placeholder { background: var(--surface-2); color: var(--muted); border: 2px dashed var(--line); box-shadow: none; }
.playing-card.active { border-color: var(--accent); }
.playing-card .rank { font-size: 34px; line-height: 1; }
.playing-card .suit { font-size: 27px; line-height: 1; margin-top: 4px; }
.playing-card.mini { width: 42px; height: 54px; border-radius: 8px; box-shadow: none; }
.playing-card.mini .rank { font-size: 19px; }
.playing-card.mini .suit { font-size: 16px; margin-top: 1px; }

.rank-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.rank-grid .choice-btn { min-height: 44px; }
.suit-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.suit-btn { min-height: 50px; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--line); font-size: 25px; color: var(--black-suit); }
.suit-btn.red { color: var(--red-suit); }
.suit-btn:disabled { opacity: 0.25; }
.suit-btn:active:not(:disabled) { transform: scale(0.96); background: var(--surface-3); }

.sticky-save {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 640px);
  padding: 14px 14px calc(10px + var(--safe-bottom));
  background: linear-gradient(to bottom, transparent, rgba(11, 13, 18, 0.96) 24%, var(--bg) 48%);
  z-index: 30;
  pointer-events: none;
}
.sticky-save .btn { width: 100%; min-height: 58px; font-size: 17px; pointer-events: auto; box-shadow: 0 12px 32px rgba(0,0,0,0.42); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-flex; align-items: center; min-height: 27px; border-radius: 999px; padding: 4px 9px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 750; border: 1px solid var(--line); }
.badge.accent { color: var(--accent); background: rgba(69,211,156,0.08); border-color: rgba(69,211,156,0.25); }
.badge.warning { color: var(--warning); background: rgba(255,202,92,0.08); border-color: rgba(255,202,92,0.24); }
.badge.danger { color: var(--danger); background: rgba(255,107,116,0.08); border-color: rgba(255,107,116,0.24); }

.hand-list { display: grid; gap: 9px; }
.hand-row {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 11px;
}
.hand-row:active { background: var(--surface-2); transform: scale(0.993); }
.hand-cards { display: flex; gap: 4px; }
.hand-main { min-width: 0; }
.hand-main strong { display: block; font-size: 14px; }
.hand-main span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hand-status { font-size: 18px; color: var(--muted); }
.hand-status.incomplete { color: var(--warning); }

.filter-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 12px; }

.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kv { background: var(--surface-2); border-radius: 12px; padding: 10px; border: 1px solid var(--line); }
.kv span { display: block; color: var(--muted); font-size: 11px; }
.kv strong { display: block; font-size: 14px; margin-top: 4px; }

.board { display: flex; justify-content: center; align-items: center; gap: 5px; min-height: 62px; padding: 8px; border-radius: 14px; background: #0f131a; border: 1px solid var(--line); }
.board-divider { width: 1px; height: 40px; background: var(--line); margin: 0 3px; }

.street-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.street-tab { min-height: 40px; border-radius: 11px; background: var(--surface-2); color: var(--muted); font-weight: 800; border: 1px solid var(--line); }
.street-tab.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.action-list { display: grid; gap: 7px; margin-top: 10px; }
.action-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; }
.action-row strong { display: block; font-size: 13px; }
.action-row span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.action-delete { width: 36px; height: 36px; border-radius: 10px; background: rgba(255,107,116,0.1); color: var(--danger); }

.floating-hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin-top: 8px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(69,211,156,0.11); }
.textarea { min-height: 96px; resize: vertical; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.field { margin-bottom: 11px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 5px 2px; }

.schedule-list { display: grid; gap: 8px; }
.schedule-row { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.schedule-row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.schedule-row-head strong { font-size: 13px; }
.schedule-row-actions { display: flex; gap: 5px; }
.schedule-row-actions button { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-3); color: var(--text); }
.schedule-fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.schedule-fields.break-fields { grid-template-columns: 1fr; }
.schedule-fields .input { min-height: 42px; padding: 7px 8px; text-align: center; font-size: 13px; }
.schedule-field-label { text-align: center; color: var(--muted); font-size: 10px; margin-bottom: 3px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: 14px; border: 1px solid var(--line); }
.segmented button { min-height: 40px; border-radius: 10px; color: var(--muted); background: transparent; font-weight: 750; }
.segmented button.selected { background: var(--surface-3); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }

.tournament-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; margin-bottom: 8px; }
.tournament-row strong { display: block; font-size: 14px; }
.tournament-row span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.tournament-actions { display: flex; gap: 6px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.64);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px 12px calc(12px + var(--safe-bottom));
}
.modal {
  width: min(100%, 620px);
  max-height: min(88dvh, 780px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
  padding: 16px;
  animation: modalUp 0.18s ease-out;
}
@keyframes modalUp { from { transform: translateY(18px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal h2 { margin: 0; font-size: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.modal-close { width: 38px; height: 38px; border-radius: 11px; background: var(--surface-2); color: var(--text); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.modal-actions.one { grid-template-columns: 1fr; }

.numeric-display { min-height: 66px; display: grid; place-items: center; background: #0e1218; border: 1px solid var(--line); border-radius: 15px; font-size: 31px; font-weight: 850; font-variant-numeric: tabular-nums; margin-bottom: 9px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { min-height: 54px; border-radius: 14px; background: var(--surface-2); color: var(--text); font-size: 19px; font-weight: 750; border: 1px solid var(--line); }
.keypad button:active { background: var(--surface-3); transform: scale(0.97); }

.sync-item { width: 100%; min-height: 50px; border-radius: 13px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); text-align: left; padding: 10px 12px; margin-bottom: 7px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sync-item.selected { border-color: var(--accent); background: rgba(69,211,156,0.09); }
.sync-item span { color: var(--muted); font-size: 12px; }
.sync-remaining { display: grid; grid-template-columns: 48px 48px 1fr 48px 48px; gap: 6px; align-items: center; margin-top: 12px; }
.sync-remaining button { height: 48px; border-radius: 12px; background: var(--surface-2); color: var(--text); font-weight: 800; }
.sync-remaining strong { text-align: center; font-size: 24px; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  z-index: 200;
  max-width: calc(100vw - 28px);
  background: #f4f6fa;
  color: #11151d;
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  font-size: 13px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.notice { border-radius: 14px; padding: 11px 12px; background: rgba(114,167,255,0.08); border: 1px solid rgba(114,167,255,0.24); color: #c9dcff; font-size: 12px; line-height: 1.6; }
.notice.warning { background: rgba(255,202,92,0.08); border-color: rgba(255,202,92,0.24); color: #ffe1a0; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }
.spacer-8 { height: 8px; }
.spacer-12 { height: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

@media (max-width: 370px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .rank-grid { grid-template-columns: repeat(7, 1fr); gap: 5px; }
  .choice-grid { gap: 6px; }
  .stack-controls { grid-template-columns: repeat(4, 40px); }
  .stack-controls button { width: 40px; height: 40px; }
  .schedule-fields { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
