:root {
  color-scheme: dark;
  --bg: #090d16;
  --surface: #111827;
  --soft: #1f2937;
  --soft-2: #182231;
  --ink: #f3f4f6;
  --muted: #9ca3af;
  --accent: #6366f1;
  --accent-soft: #2e2e5c;
  --ok: #34d399;
  --danger: #fb7185;
  --line: #374151;
  --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.7), 0 8px 15px -6px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid rgba(99, 102, 241, 0.55);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  width: min(680px, calc(100% - 24px));
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
}

h1 {
  font-size: clamp(24px, 6vw, 38px);
  line-height: 1.1;
  font-weight: 900;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 8px;
  background: var(--soft);
}

.seg-button {
  min-height: 58px;
  padding: 0 8px;
  background: transparent;
  color: var(--ink);
  font-size: clamp(15px, 3.8vw, 19px);
  font-weight: 900;
}

.seg-button.is-active {
  background: var(--accent);
  color: #fff;
}

.progress-strip {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 900;
}

.progress-strip strong {
  color: var(--ink);
  font-size: 27px;
  line-height: 1;
}

.restart-button {
  justify-self: end;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.progress-track {
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  background: var(--line);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 160ms ease;
}

.flash-card {
  position: relative;
  overflow: hidden;
  padding: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
}

.card-title-wrap {
  min-width: 0;
}

.card-title {
  color: var(--ink);
  font-size: clamp(52px, 17vw, 112px);
  line-height: 0.95;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.card-title.is-long {
  font-size: clamp(42px, 13vw, 72px);
  line-height: 1.02;
}

.card-title[hidden] {
  display: none;
}

.card-count {
  flex: 0 0 auto;
  min-width: 52px;
  height: 46px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 21px;
  font-weight: 900;
}

.prompt-grid {
  display: grid;
  gap: 8px;
}

.position-cue {
  display: grid;
  gap: 4px;
}

.micro-label {
  padding-left: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.cue-row {
  display: grid;
  grid-template-columns: 1.08fr repeat(4, 1fr);
  gap: 3px;
}

.cue-cell {
  min-width: 0;
  height: 50px;
  display: grid;
  place-items: center;
  padding: 0 5px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  font-size: clamp(15px, 4.4vw, 22px);
  font-weight: 900;
}

.cue-cell.is-prep {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}

.cue-cell.is-target {
  border-color: var(--danger);
  background: rgba(251, 113, 133, 0.3);
  color: var(--danger);
}

.miss-count {
  padding: 3px 0 0 3px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 900;
}

.compact-prompt {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 4px;
}

.compact-prompt div {
  min-height: 54px;
  padding: 7px 9px;
  background: var(--soft);
}

.compact-prompt small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.compact-prompt strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
}

.answer-panel {
  display: grid;
  gap: 8px;
}

.answer-grid {
  display: grid;
  gap: 6px;
}

.drop-target {
  width: 100%;
  min-height: 62px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  font-size: clamp(20px, 6vw, 34px);
  font-weight: 900;
}

.drop-target.has-value,
.drop-target.is-hot {
  border-width: 2px;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}

.block-tray {
  display: grid;
  gap: 6px;
}

.block-tray.is-value {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choice-block {
  min-width: 0;
  min-height: 58px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  font-size: clamp(16px, 4.2vw, 22px);
  line-height: 1.12;
  font-weight: 900;
  overflow-wrap: anywhere;
  user-select: none;
}

.choice-block.is-selected {
  border-width: 2px;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.chooser-guide {
  margin-bottom: 2px;
}

.floor-chooser {
  display: grid;
  gap: 6px;
}

.floor-button {
  min-height: 46px;
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 24px;
  font-weight: 900;
}

.matrix-reset {
  min-height: 36px;
  padding: 0 8px;
  background: var(--soft);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 900;
}

.location-matrix {
  display: grid;
  grid-template-columns: 1.18fr repeat(4, 1fr);
  gap: 3px;
}

.matrix-cell {
  min-width: 0;
  height: 42px;
  padding: 0 3px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  font-size: 20px;
  font-weight: 900;
}

.matrix-cell.is-label {
  background: var(--soft-2);
  color: var(--ink);
  font-size: clamp(11px, 3vw, 14px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-cell:disabled {
  opacity: 1;
  cursor: default;
}

.matrix-cell.is-selected {
  border-width: 2px;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.key-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.plain-button {
  min-width: 86px;
  min-height: 48px;
  padding: 0 16px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
}

.plain-button.danger {
  background: var(--danger);
}

.plain-button.accent {
  background: var(--accent);
}

.recent-result {
  min-height: 48px;
  margin-top: 8px;
  padding: 11px 12px;
  background: var(--soft);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 900;
}

.recent-result.is-ok {
  border: 1px solid var(--ok);
  background: rgba(52, 211, 153, 0.12);
  color: var(--ok);
}

.recent-result.is-wrong {
  border: 1px solid var(--danger);
  background: rgba(251, 113, 133, 0.14);
  color: var(--danger);
}

.touch-nav {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  pointer-events: none;
}

.touch-btn {
  pointer-events: auto;
  width: 34px;
  height: 110px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: rgba(31, 41, 55, 0.35);
  color: var(--muted);
  font-size: 38px;
  font-weight: 900;
  opacity: 0.42;
}

.touch-btn:active {
  opacity: 1;
  background: var(--accent);
  color: var(--ink);
}

.history-bar {
  margin-top: 10px;
  opacity: 0.45;
  transition: opacity 0.2s ease;
}

.history-bar:hover,
.history-bar:focus-within {
  opacity: 1;
}

.history-bar h3 {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 15px;
}

.history-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 3px;
}

.history-card {
  flex: 0 0 auto;
  max-width: min(330px, 82vw);
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.history-card.is-ok b {
  color: var(--ok);
}

.history-card.is-wrong b {
  color: var(--danger);
}

@media (min-width: 821px) {
  .app-shell {
    padding-top: 22px;
  }

  .touch-btn {
    opacity: 0.2;
  }

  .touch-btn:hover,
  .touch-btn:focus-visible {
    opacity: 0.78;
  }
}

@media (max-width: 430px) {
  .app-shell {
    width: min(100% - 20px, 680px);
  }

  .seg-button {
    min-height: 48px;
  }

  .progress-strip {
    gap: 10px;
  }

  .flash-card {
    padding: 12px;
  }

  .card-head {
    margin-bottom: 6px;
  }

  .card-title {
    font-size: clamp(46px, 15vw, 72px);
  }

  .card-title.is-long {
    font-size: clamp(34px, 10vw, 48px);
  }

  .card-count {
    min-width: 48px;
    height: 42px;
  }

  .cue-cell {
    height: 46px;
    font-size: 16px;
  }

  .drop-target {
    min-height: 58px;
  }

  .choice-block {
    min-height: 54px;
    font-size: 16px;
  }

  .floor-button {
    min-height: 39px;
    font-size: 22px;
  }

  .matrix-cell {
    height: 38px;
  }

  .action-row {
    grid-template-columns: 1fr 1fr;
  }

  .key-hint {
    grid-column: 1 / -1;
  }

  .plain-button {
    width: 100%;
  }

  .touch-btn {
    width: 30px;
    height: 96px;
    font-size: 34px;
  }

  .recent-result {
    min-height: 42px;
    padding: 9px 10px;
  }
}
