:root {
  --ink: #2b1712;
  --paper: #fff8e8;
  --cream: #f8edcf;
  --yellow: #f6c945;
  --yellow-dark: #d99c1c;
  --red: #d93b2b;
  --red-dark: #98261e;
  --green: #2e7653;
  --white: #fffdf7;
  --shadow: 0 18px 0 rgba(83, 44, 23, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--yellow);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background-color: var(--yellow);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.13) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.13) 2px, transparent 2px);
  background-size: 36px 36px;
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", Arial, sans-serif;
  overflow-x: hidden;
}

button,
kbd {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 4px solid var(--green);
  outline-offset: 3px;
}

.page-shell {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

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

.brand {
  display: flex;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
}

.brand__logo {
  display: block;
  width: clamp(148px, 15vw, 184px);
  height: auto;
}

.topbar__actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-button,
.text-button {
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}

.icon-button:active,
.text-button:active,
.primary-button:active {
  box-shadow: none;
  transform: translate(3px, 3px);
}

.icon-button {
  display: grid;
  width: 46px;
  height: 42px;
  padding: 9px;
  place-items: center;
  border-radius: 12px;
}

.icon {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.3;
}

.icon--muted,
.is-muted .icon--sound {
  display: none;
}

.is-muted .icon--muted {
  display: block;
}

.text-button {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.game-card {
  position: relative;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: var(--shadow), 7px 7px 0 var(--ink);
}

.hud {
  display: flex;
  min-height: 116px;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 18px 28px;
  border-bottom: 4px solid var(--ink);
  background: var(--paper);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--red);
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hud h1 {
  margin: 0;
  font-size: clamp(27px, 3vw, 42px);
  font-weight: 1000;
  letter-spacing: -0.07em;
  line-height: 0.95;
  text-transform: uppercase;
}

.hud__stats {
  display: flex;
  align-items: stretch;
}

.stat,
.lives {
  min-width: 104px;
  padding: 4px 18px;
  border-left: 2px dashed rgba(43, 23, 18, 0.28);
}

.stat span,
.lives > span {
  display: block;
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.13em;
  opacity: 0.58;
  text-transform: uppercase;
}

.stat strong {
  font-size: 25px;
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.lives {
  min-width: 132px;
}

.lives__icons {
  display: flex;
  gap: 7px;
}

.lives__icons i {
  position: relative;
  width: 25px;
  height: 20px;
  border: 2px solid var(--ink);
  border-radius: 12px 12px 7px 7px;
  background: var(--red);
  transform: rotate(-2deg);
  transition: opacity 180ms ease, transform 180ms ease;
}

.lives__icons i::before {
  position: absolute;
  top: 5px;
  right: 3px;
  left: 3px;
  height: 2px;
  border-radius: 2px;
  background: var(--yellow);
  box-shadow: 0 4px 0 #68a946;
  content: "";
}

.lives__icons i.is-lost {
  opacity: 0.18;
  transform: scale(0.75) rotate(15deg);
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  background: #f1b936;
  isolation: isolate;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  touch-action: none;
}

.screen {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  padding: 22px;
  place-items: center;
  background: rgba(43, 23, 18, 0.56);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.screen--visible {
  opacity: 1;
  pointer-events: auto;
}

.screen__panel {
  position: relative;
  width: min(560px, 92%);
  padding: clamp(25px, 3vw, 38px);
  border: 4px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
  text-align: center;
  transform: rotate(-0.7deg);
}

.screen__panel--small {
  width: min(480px, 92%);
}

.screen__panel h2,
.rules-dialog h2 {
  margin: 0;
  font-size: clamp(32px, 4.2vw, 50px);
  font-weight: 1000;
  letter-spacing: -0.065em;
  line-height: 0.96;
  text-transform: uppercase;
}

.screen__panel p:not(.eyebrow):not(.new-record) {
  margin: 19px 0 24px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  opacity: 0.75;
}

.screen__panel strong {
  color: var(--red);
  font-size: 1.1em;
}

.screen__sticker {
  position: absolute;
  top: -23px;
  right: -20px;
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: var(--white);
  background: var(--red);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 20px;
  font-weight: 1000;
  transform: rotate(12deg);
}

.primary-button {
  display: inline-flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 0 24px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  color: var(--white);
  background: var(--red);
  box-shadow: 5px 5px 0 var(--ink);
  cursor: pointer;
  font-size: 15px;
  font-weight: 1000;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.primary-button span {
  font-size: 22px;
}

.key-hint {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 25px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

kbd {
  display: inline-grid;
  min-width: 25px;
  height: 25px;
  margin-right: 3px;
  padding: 0 5px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--white);
  box-shadow: 1px 2px 0 var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.new-record {
  width: max-content;
  margin: -10px auto 18px;
  padding: 7px 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  background: var(--yellow);
  font-size: 13px;
  font-weight: 1000;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform: rotate(-2deg);
}

.combo-badge {
  position: absolute;
  z-index: 4;
  top: 23px;
  left: 50%;
  padding: 9px 16px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  color: var(--white);
  background: var(--green);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 16px;
  font-weight: 1000;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -30px) rotate(-2deg);
  transition: opacity 180ms ease, transform 180ms ease;
}

.combo-badge.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) rotate(-2deg);
}

.footer-note {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 25px;
  flex-wrap: wrap;
}

.footer-note span {
  padding: 8px 12px;
  border: 2px solid rgba(43, 23, 18, 0.65);
  border-radius: 999px;
  background: rgba(255, 248, 232, 0.55);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.footer-note b {
  color: var(--red-dark);
}

.rules-dialog {
  width: min(570px, calc(100% - 30px));
  padding: clamp(28px, 5vw, 48px);
  border: 4px solid var(--ink);
  border-radius: 22px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
}

.rules-dialog::backdrop {
  background: rgba(43, 23, 18, 0.7);
}

.rules-dialog h2 {
  font-size: clamp(34px, 7vw, 54px);
}

.rules-dialog ol {
  margin: 28px 0;
  padding: 0;
  list-style: none;
}

.rules-dialog li {
  display: flex;
  gap: 15px;
  align-items: flex-start;
  padding: 13px 0;
  border-top: 2px dashed rgba(43, 23, 18, 0.2);
}

.rules-dialog li span {
  color: var(--red);
  font-size: 15px;
  font-weight: 1000;
}

.rules-dialog li p {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}

.dialog-close {
  position: absolute;
  top: 13px;
  right: 15px;
  width: 38px;
  height: 38px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 30px;
  font-weight: 800;
}

.stage-wrap.is-shaking {
  animation: shake 240ms steps(2, end);
}

@keyframes shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

@media (max-width: 850px) {
  .page-shell {
    width: min(100% - 20px, 760px);
    padding-top: 10px;
  }

  .topbar {
    margin-bottom: 10px;
  }

  .hud {
    display: block;
    padding: 14px 16px 12px;
  }

  .hud__intro {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 13px;
  }

  .hud__intro .eyebrow {
    order: 2;
  }

  .hud h1 {
    font-size: 27px;
  }

  .hud__stats {
    justify-content: space-between;
    border-top: 2px dashed rgba(43, 23, 18, 0.2);
    padding-top: 10px;
  }

  .stat,
  .lives {
    min-width: 0;
    padding: 2px 10px;
  }

  .stat:first-child {
    border-left: 0;
    padding-left: 0;
  }

  .stat strong {
    font-size: 20px;
  }

  .lives {
    padding-right: 0;
  }

  .lives__icons i {
    width: 21px;
    height: 18px;
  }

}

@media (max-width: 560px) {
  .page-shell {
    width: 100%;
    min-width: 0;
    max-width: 100vw;
    padding: 0 0 18px;
  }

  .topbar {
    min-height: 58px;
    padding: 5px max(12px, env(safe-area-inset-right)) 5px max(12px, env(safe-area-inset-left));
  }

  .brand {
    min-width: 0;
  }

  .topbar__actions {
    flex: 0 0 auto;
  }

  .brand__logo {
    width: 138px;
  }

  .text-button {
    width: 46px;
    min-width: 46px;
    min-height: 42px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
  }

  .text-button::after {
    content: "?";
    font-size: 20px;
    font-weight: 1000;
  }

  .game-card {
    width: 100%;
    min-width: 0;
    max-width: 100vw;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .hud__intro .eyebrow,
  .stat:nth-child(3) {
    display: none;
  }

  .hud__stats {
    width: 100%;
    min-width: 0;
    gap: 0;
  }

  .stat,
  .lives {
    flex: 1 1 0;
    min-width: 0;
    border-left: 2px dashed rgba(43, 23, 18, 0.22);
  }

  .lives {
    flex-grow: 1.25;
  }

  .screen {
    padding: 12px;
  }

  .screen__panel {
    width: 92%;
    padding: 18px 14px 16px;
    box-shadow: 5px 5px 0 var(--ink);
    transform: rotate(-0.35deg);
  }

  .screen__panel .eyebrow {
    margin-bottom: 6px;
    font-size: 10px;
    letter-spacing: 0.14em;
  }

  .screen__panel h2 {
    font-size: clamp(29px, 8.5vw, 36px);
  }

  .screen__panel p:not(.eyebrow):not(.new-record) {
    margin: 11px 0 14px;
    font-size: 13px;
    line-height: 1.35;
  }

  .screen__sticker {
    top: -16px;
    right: -4px;
    width: 44px;
    height: 44px;
    font-size: 14px;
  }

  .primary-button {
    min-height: 48px;
    padding: 0 20px;
    font-size: 12px;
  }

  .key-hint {
    display: none;
  }

  .footer-note {
    margin-top: 14px;
    padding: 0 10px;
  }
}

@media (max-width: 560px) and (orientation: portrait) {
  .stage-wrap {
    display: grid;
    height: min(calc(100vw * 4 / 3), calc(100dvh - 150px));
    min-height: min(400px, calc(100dvh - 150px));
    place-items: center;
  }

  #gameCanvas {
    width: auto;
    max-width: 100%;
    height: 100%;
    aspect-ratio: 3 / 4;
  }
}

@media (min-width: 851px) and (max-height: 940px) {
  .page-shell {
    width: min(1060px, calc(100% - 36px));
    padding-top: 12px;
  }

  .topbar {
    min-height: 52px;
    margin-bottom: 10px;
  }

  .hud {
    min-height: 102px;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .footer-note {
    margin-top: 14px;
  }
}

@media (max-height: 700px) and (orientation: landscape) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .page-shell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
  }

  .topbar,
  .footer-note {
    display: none;
  }

  .game-card {
    height: 100%;
    border-radius: 14px;
    box-shadow: none;
  }

  .hud {
    position: absolute;
    z-index: 6;
    top: 0;
    left: 50%;
    display: block;
    width: min(720px, 100%);
    min-height: 54px;
    padding: 6px 12px;
    border-right: 3px solid var(--ink);
    border-bottom: 3px solid var(--ink);
    border-left: 3px solid var(--ink);
    border-radius: 0 0 13px 13px;
    background: rgba(255, 248, 232, 0.94);
    transform: translateX(-50%);
  }

  .hud__intro {
    display: none;
  }

  .hud__stats {
    display: flex;
    justify-content: center;
    padding: 0;
    border: 0;
  }

  .stat,
  .lives {
    min-width: 86px;
    padding: 0 12px;
  }

  .stat:first-child {
    border-left: 0;
  }

  .stat span,
  .lives > span {
    margin-bottom: 1px;
    font-size: 8px;
  }

  .stat strong {
    font-size: 17px;
  }

  .lives__icons {
    gap: 4px;
  }

  .lives__icons i {
    width: 18px;
    height: 15px;
  }

  .stage-wrap {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
  }

  #gameCanvas {
    width: auto;
    max-width: 100%;
    height: 100%;
    aspect-ratio: 16 / 9;
  }

  .screen {
    padding: 56px 8px 8px;
  }

  .screen__panel,
  .screen__panel--small {
    width: min(450px, 82%);
    padding: 10px 13px 9px;
    border-width: 3px;
    border-radius: 14px;
    box-shadow: 4px 4px 0 var(--ink);
  }

  .screen__panel .eyebrow {
    margin-bottom: 3px;
    font-size: 9px;
  }

  .screen__panel h2 {
    font-size: clamp(24px, 5.6vh, 31px);
  }

  .screen__panel p:not(.eyebrow):not(.new-record) {
    margin: 5px 0 7px;
    font-size: 11px;
    line-height: 1.2;
  }

  .screen__sticker {
    top: -11px;
    right: -10px;
    width: 43px;
    height: 43px;
    font-size: 13px;
  }

  .primary-button {
    min-height: 38px;
    padding: 0 16px;
    font-size: 10px;
  }

  .key-hint {
    display: none;
  }

}

@media (max-width: 360px) and (orientation: portrait),
       (max-height: 640px) and (orientation: portrait) {
  .topbar {
    min-height: 52px;
  }

  .brand__logo {
    width: 124px;
  }

  .hud {
    padding-top: 10px;
    padding-bottom: 9px;
  }

  .hud__intro {
    margin-bottom: 8px;
  }

  .hud h1 {
    font-size: 23px;
  }

  .stage-wrap {
    min-height: 0;
  }
}

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