:root {
  --paper: #f8f3ea;
  --ink: #1f2430;
  --muted: #69707f;
  --line: #d9d2c5;
  --panel: #fffaf1;
  --teal: #087f8c;
  --coral: #de5b45;
  --gold: #f2b84b;
  --green: #337357;
  --shadow: 0 18px 45px rgba(45, 38, 30, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(8, 127, 140, 0.14), rgba(242, 184, 75, 0.22)),
    var(--paper);
}

.lock-screen.hidden {
  display: none;
}

.lock-panel {
  display: grid;
  gap: 12px;
  width: min(100%, 380px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.lock-panel h1 {
  font-size: 2.6rem;
}

.lock-panel input {
  width: 100%;
  min-height: 52px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 1.4rem;
  font-weight: 800;
}

.app-shell {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.2rem;
}

.status-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-strip span {
  min-width: 86px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.8);
  text-align: center;
  color: var(--muted);
}

.status-strip strong {
  display: block;
  color: var(--ink);
  font-size: 1.25rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.setup-grid,
.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.panel,
.practice-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-heading,
.panel-actions,
.game-actions,
.round-stats,
.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-heading,
.panel-actions,
.round-stats {
  justify-content: space-between;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
  min-height: 340px;
  align-content: start;
}

.photo-grid.empty {
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.empty-state {
  max-width: 260px;
  text-align: center;
  color: var(--muted);
}

.empty-frame {
  width: 132px;
  aspect-ratio: 4 / 3;
  margin: 0 auto 12px;
  border-radius: 8px;
  border: 8px solid #fff;
  background:
    linear-gradient(135deg, rgba(8, 127, 140, 0.25), rgba(242, 184, 75, 0.5)),
    linear-gradient(45deg, transparent 48%, rgba(31, 36, 48, 0.13) 50%, transparent 52%);
  box-shadow: 0 10px 24px rgba(31, 36, 48, 0.16);
}

.thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #e9e0d2;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb.used::after {
  content: "used";
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(31, 36, 48, 0.78);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
}

.file-button,
.primary,
.secondary,
.quiet {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 800;
}

.file-button,
.primary {
  background: var(--teal);
  color: #fff;
}

.file-button input {
  display: none;
}

.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.quiet {
  background: transparent;
  color: var(--muted);
}

.panel-actions {
  margin-top: 14px;
  flex-wrap: wrap;
}

.settings-panel {
  display: grid;
  gap: 16px;
}

.control-row {
  flex-wrap: wrap;
}

.control-row input {
  width: 74px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 800;
}

.mode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.mode-picker legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: var(--muted);
}

.mode-picker label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 800;
}

.setup-notice {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.setup-notice.good {
  color: var(--green);
}

.setup-notice.try {
  color: var(--coral);
}

.reveal-stage {
  min-width: 0;
}

.photo-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(222, 91, 69, 0.2), rgba(8, 127, 140, 0.18)),
    #d7d0c3;
  box-shadow: var(--shadow);
}

.photo-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scale(1.03);
  filter: blur(28px) saturate(0.7);
  transition: filter 360ms ease, transform 360ms ease;
}

.tile-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  pointer-events: none;
}

.tile {
  background:
    linear-gradient(135deg, rgba(248, 243, 234, 0.96), rgba(232, 221, 204, 0.96)),
    repeating-linear-gradient(45deg, rgba(8, 127, 140, 0.16) 0 12px, transparent 12px 24px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  transition: opacity 280ms ease, transform 280ms ease;
}

.tile.revealed {
  opacity: 0;
  transform: scale(0.88);
}

.complete-badge {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
  transition: opacity 220ms ease, transform 220ms ease;
}

.complete-badge.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.progress-track {
  overflow: hidden;
  height: 14px;
  margin-top: 14px;
  border-radius: 999px;
  background: #e2d8c8;
}

.progress-track div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--coral), var(--gold), var(--teal));
  transition: width 280ms ease;
}

.practice-panel {
  padding: 16px;
}

.round-stats {
  margin-bottom: 14px;
  color: var(--muted);
}

.problem-card {
  display: grid;
  place-items: center;
  min-height: 228px;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.problem-text {
  font-size: clamp(3rem, 10vw, 6.8rem);
  line-height: 1;
  font-weight: 950;
}

.answer-display {
  display: grid;
  place-items: center;
  width: min(100%, 260px);
  min-height: 64px;
  margin-top: 14px;
  border-bottom: 5px solid var(--ink);
  font-size: 2.4rem;
  font-weight: 900;
}

.feedback {
  min-height: 28px;
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.feedback.good {
  color: var(--green);
}

.feedback.try {
  color: var(--coral);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.keypad button {
  min-height: 64px;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 1.4rem;
  font-weight: 900;
  box-shadow: 0 5px 0 #d6ccbd;
}

.keypad button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #d6ccbd;
}

.keypad [data-key="submit"] {
  background: var(--coral);
  border-color: var(--coral);
  color: #fff;
  box-shadow: 0 5px 0 #9f392d;
}

.game-actions {
  margin-top: 14px;
  flex-wrap: wrap;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: start;
  }

  .setup-grid,
  .game-grid {
    grid-template-columns: 1fr;
  }

  .photo-grid {
    min-height: 240px;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  }

  .practice-panel {
    padding: 12px;
  }

  .problem-card {
    min-height: 180px;
  }
}

@media (max-width: 560px) {
  .topbar {
    display: grid;
  }

  .status-strip {
    justify-content: stretch;
  }

  .status-strip span {
    flex: 1;
  }

  .panel-heading,
  .panel-actions,
  .round-stats {
    align-items: stretch;
    flex-direction: column;
  }

  .file-button,
  .primary,
  .secondary,
  .quiet {
    width: 100%;
  }

  .mode-picker {
    grid-template-columns: 1fr;
  }
}
