:root {
  color-scheme: light;
  --ink: #24150f;
  --muted: #6f5b4f;
  --cream: #fff7ec;
  --paper: #fffdf8;
  --coffee: #5c3322;
  --espresso: #1d100c;
  --orange: #e66b2d;
  --amber: #f4b63f;
  --green: #6f8f55;
  --line: rgba(36, 21, 15, 0.14);
  --shadow: 0 24px 70px rgba(58, 30, 16, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(244, 182, 63, 0.22), transparent 28%),
    linear-gradient(145deg, #fff9ef 0%, #f4dfc4 45%, #c68c54 100%);
  color: var(--ink);
}

button, a { -webkit-tap-highlight-color: transparent; }

.shell {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 8px 10px 14px;
}

.hero {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  gap: 6px 10px;
  align-items: center;
  padding: 4px 4px 8px;
}

.brand {
  display: inline-flex;
  width: fit-content;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.68);
  color: var(--coffee);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  font-size: clamp(28px, 4.8vw, 48px);
  line-height: 0.95;
  letter-spacing: 0;
}

.hero p {
  grid-column: 1 / 3;
  grid-row: 2;
  max-width: none;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.hero-actions {
  grid-column: 3;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 6px;
  align-self: center;
}

.primary, .ghost, .control {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.primary {
  padding: 9px 14px;
  background: var(--espresso);
  color: var(--cream);
  box-shadow: 0 10px 24px rgba(29, 16, 12, 0.24);
}

.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.58);
  color: var(--ink);
  text-decoration: none;
}

.ghost.utility {
  min-width: 88px;
  background: rgba(255, 253, 248, 0.84);
}

.primary:active, .ghost:active, .control:active { transform: translateY(1px) scale(0.99); }

.game-card, .lesson-card, .result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.game-card {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.85fr);
  grid-template-areas:
    "top top"
    "canvas coach"
    "canvas stage"
    "controls moment"
    "meters taste"
    "dials taste";
  gap: 8px;
  padding: 10px;
}

.roaster-top {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0;
}

.label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.phase {
  font-size: 19px;
  font-weight: 900;
}

.score-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--espresso);
  color: var(--cream);
  font-weight: 900;
}

.roaster-pills {
  display: flex;
  align-items: center;
  gap: 7px;
}

.heat-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid rgba(230, 107, 45, 0.28);
  border-radius: 999px;
  background: #fff1df;
  color: var(--coffee);
  font-weight: 900;
}

.heat-pill strong {
  color: var(--ink);
}

.coach-card {
  grid-area: coach;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  margin: 0;
  padding: 10px;
  border: 2px solid rgba(230, 107, 45, 0.28);
  border-radius: 8px;
  background: #fff1df;
}

.coach-title {
  margin-top: 4px;
  font-size: clamp(18px, 4vw, 28px);
  line-height: 1.05;
  font-weight: 950;
}

.coach-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.target-box {
  min-width: 92px;
  padding: 10px;
  border-radius: 8px;
  background: var(--espresso);
  color: var(--cream);
  text-align: center;
}

.target-box span {
  display: block;
  color: rgba(255,247,236,0.72);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.target-box strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
}

.stage-track {
  grid-area: stage;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0;
}

.stage-step {
  min-height: 48px;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.62);
  color: var(--muted);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.stage-step span,
.stage-step strong {
  display: block;
  text-align: center;
}

.stage-step span {
  font-size: 12px;
  font-weight: 900;
}

.stage-step strong {
  margin-top: 4px;
  font-size: 12px;
}

.stage-step.active {
  border-color: rgba(230, 107, 45, 0.7);
  background: #fff0dc;
  color: var(--ink);
  transform: translateY(-1px);
}

canvas {
  grid-area: canvas;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 720 / 310;
  border-radius: 8px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.16), transparent 28%),
    linear-gradient(160deg, #3b2118 0%, #160d0a 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}

.moment-card {
  grid-area: moment;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin-top: 0;
  padding: 9px 11px;
  border: 1px solid rgba(244, 182, 63, 0.42);
  border-radius: 8px;
  background: #fff8df;
  color: var(--coffee);
}

.moment-card span {
  font-size: 24px;
  line-height: 1;
}

.moment-card strong {
  font-size: 14px;
  line-height: 1.35;
}

.meters {
  grid-area: meters;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
}

.meter {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.meter strong {
  display: block;
  margin: 3px 0 8px;
  font-size: 18px;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(36, 21, 15, 0.12);
}

.bar i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.25s ease;
}

.bar.hot i { background: var(--orange); }
.bar.gold i { background: var(--amber); }

.taste-card {
  grid-area: taste;
  margin: 0;
  padding: 13px;
  border: 1px solid rgba(111, 143, 85, 0.36);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.64);
}

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

.taste-head strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
}

.taste-head span {
  max-width: 260px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-align: right;
}

.taste-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.taste-meter span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.taste-meter i {
  display: block;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(36, 21, 15, 0.12);
}

.taste-meter b {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.25s ease;
}

#bodyBar { background: var(--amber); }
#roastBar { background: var(--coffee); }

.controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 7px;
}

.control {
  padding: 10px 7px;
  background: #f7e6ce;
  color: var(--ink);
}

.control.hot { background: var(--orange); color: white; }
.control.finish { background: var(--espresso); color: var(--cream); }
.control:disabled { opacity: 0.45; cursor: not-allowed; }
.control.pulse,
.primary.pulse,
.ghost.pulse { animation: pressPulse 0.42s ease; }

@keyframes pressPulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.035); }
  100% { transform: scale(1); }
}

.dial-row {
  grid-area: dials;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
  margin-top: 0;
}

.dial {
  padding: 10px;
  border-radius: 8px;
  background: rgba(36, 21, 15, 0.07);
  text-align: center;
}

.dial span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.dial strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
}

.rules-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.rule {
  min-height: 92px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.66);
}

.rule strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.rule span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.lesson-card, .result-card {
  margin-top: 14px;
  padding: 16px;
}

.lesson-card p, .result-card p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.result-card h2 {
  margin: 6px 0 8px;
  font-size: 30px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.badge {
  padding: 8px 10px;
  border-radius: 999px;
  background: #f2ddc1;
  color: var(--coffee);
  font-size: 13px;
  font-weight: 850;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0 4px;
}

.result-stat {
  padding: 10px;
  border-radius: 8px;
  background: rgba(36, 21, 15, 0.07);
  text-align: center;
}

.result-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.result-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.result-actions .primary,
.result-actions .ghost {
  flex: 1 1 150px;
}

.poster-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.poster {
  width: min(620px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: center;
  box-shadow: var(--shadow);
}

.poster h1 { font-size: clamp(48px, 12vw, 86px); }
.poster p { color: var(--muted); font-size: 18px; line-height: 1.5; }
.poster img { width: min(340px, 78vw); margin: 20px auto; display: block; }
.poster strong { display: block; font-size: 18px; }

.footer-links {
  display: flex;
  justify-content: flex-end;
  margin: 10px 0 0;
}

.footer-links a {
  color: var(--coffee);
  font-size: 12px;
  font-weight: 850;
  text-decoration: none;
}

@media (max-width: 720px) {
  .shell { padding: 6px; }
  .hero {
    grid-template-columns: auto 1fr;
    padding: 3px 2px 6px;
    gap: 5px 8px;
  }
  .brand { font-size: 11px; padding: 5px 9px; }
  h1 {
    grid-column: 2;
    grid-row: 1;
    font-size: 28px;
  }
  .hero p {
    display: none;
    max-width: 100%;
    font-size: 12px;
    line-height: 1.25;
  }
  .hero-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: 1fr 1fr auto;
  }
  .hero-actions .primary, .hero-actions .ghost {
    min-width: 0;
    padding: 8px 7px;
    font-size: 12px;
    justify-content: center;
  }
  .game-card {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "canvas"
      "controls"
      "coach"
      "stage"
      "moment"
      "meters"
      "taste"
      "dials";
    gap: 6px;
    padding: 8px;
  }
  .roaster-top { margin-bottom: 0; }
  .phase { font-size: 17px; }
  .score-pill,
  .heat-pill {
    padding: 6px 8px;
    font-size: 13px;
  }
  .coach-card {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 7px;
  }
  .coach-title { font-size: 18px; }
  .coach-card p {
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.25;
  }
  .target-box { min-width: 74px; padding: 8px; }
  .target-box strong { font-size: 15px; }
  .stage-track { grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .stage-step { min-height: 36px; padding: 5px 4px; }
  .stage-step span { font-size: 11px; }
  .stage-step strong { font-size: 10px; margin-top: 2px; }
  canvas { aspect-ratio: 720 / 300; }
  .controls { gap: 5px; margin-top: 6px; }
  .control { min-height: 40px; padding: 8px 4px; font-size: 12px; }
  .moment-card {
    min-height: 36px;
    padding: 7px 9px;
  }
  .moment-card span { font-size: 20px; }
  .moment-card strong { font-size: 12px; }
  .meters { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .meter { padding: 6px; }
  .meter strong { font-size: 14px; margin: 2px 0 4px; }
  .bar { height: 6px; }
  .taste-card { padding: 8px; }
  .taste-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
  }
  .taste-head strong { font-size: 15px; }
  .taste-head span {
    max-width: 140px;
    margin-top: 0;
    font-size: 11px;
    line-height: 1.2;
    text-align: right;
  }
  .taste-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .taste-meter span { margin-bottom: 4px; font-size: 10px; }
  .taste-meter i { height: 6px; }
  .dial-row { grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .dial { padding: 6px 4px; }
  .dial span { font-size: 10px; }
  .dial strong { margin-top: 2px; font-size: 15px; }
  .rules-card { grid-template-columns: 1fr; }
}

@media (max-width: 720px) and (max-height: 760px) {
  .game-card { gap: 5px; }
  .coach-card p { display: none; }
  .taste-card { display: none; }
  .dial-row { display: none; }
}
