:root {
  --sky: #54b9f3;
  --paper: #fff7d6;
  --paper-deep: #ffe9a8;
  --ink: #14384a;
  --ink-soft: #456273;
  --honey: #f6b93b;
  --honey-dark: #c87820;
  --leaf: #258e57;
  --coral: #e96855;
  --shadow: rgba(15, 54, 70, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #2f91ce;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button,
canvas {
  touch-action: manipulation;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 320px;
  overflow: hidden;
  isolation: isolate;
}

.game-shell::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 22%),
    radial-gradient(circle at 50% 42%, transparent 45%, rgba(14, 55, 75, 0.12) 120%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.topbar {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  left: max(16px, env(safe-area-inset-left));
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.score-pill {
  display: flex;
  min-width: 92px;
  min-height: 49px;
  align-items: center;
  gap: 11px;
  padding: 8px 13px 8px 15px;
  border: 2px solid rgba(20, 56, 74, 0.16);
  border-radius: 16px 12px 16px 12px;
  background: rgba(255, 247, 214, 0.94);
  box-shadow: 0 5px 0 rgba(21, 70, 85, 0.16), 0 9px 24px var(--shadow);
  transform: translateY(-80px);
  transition: transform 360ms cubic-bezier(0.2, 0.9, 0.2, 1.15);
}

.topbar.is-active .score-pill {
  transform: translateY(0);
}

.score-label {
  color: var(--ink-soft);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.score-pill strong {
  min-width: 1.3ch;
  color: var(--ink);
  font-family: Georgia, serif;
  font-size: 1.65rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
}

.icon-button {
  position: relative;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid rgba(20, 56, 74, 0.16);
  border-radius: 50%;
  background: rgba(255, 247, 214, 0.94);
  box-shadow: 0 5px 0 rgba(21, 70, 85, 0.16), 0 9px 24px var(--shadow);
  color: var(--ink);
  cursor: pointer;
  opacity: 0;
  pointer-events: auto;
  transform: translateY(-80px);
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 260ms ease;
}

.topbar.is-active .icon-button {
  opacity: 1;
  transform: translateY(0);
}

.icon-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 rgba(21, 70, 85, 0.16), 0 12px 28px var(--shadow);
}

.icon-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(21, 70, 85, 0.18), 0 5px 12px var(--shadow);
}

.icon-button:focus-visible,
.primary-button:focus-visible,
#game:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 3px;
}

.pause-icon,
.pause-icon::after {
  display: block;
  width: 5px;
  height: 17px;
  border-radius: 2px;
  background: currentColor;
}

.pause-icon {
  position: relative;
  transform: translateX(-4px);
}

.pause-icon::after {
  position: absolute;
  left: 8px;
  content: "";
}

.panel {
  position: absolute;
  top: 50%;
  left: clamp(18px, 7vw, 104px);
  z-index: 3;
  width: min(390px, calc(100vw - 36px));
  padding: clamp(25px, 5vh, 42px) clamp(24px, 4vw, 40px) 26px;
  border: 3px solid rgba(20, 56, 74, 0.16);
  border-radius: 30px 24px 34px 22px;
  background: linear-gradient(145deg, rgba(255, 251, 226, 0.98), rgba(255, 238, 181, 0.97));
  box-shadow: 0 12px 0 rgba(25, 74, 84, 0.18), 0 28px 70px rgba(14, 54, 72, 0.31);
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(-50% + 24px)) rotate(-1deg) scale(0.97);
  transition: opacity 280ms ease, transform 500ms cubic-bezier(0.2, 0.8, 0.2, 1.05);
}

.intro-panel {
  position: absolute;
  top: max(58px, 9vh);
  left: 50%;
  z-index: 3;
  width: min(900px, calc(100vw - 36px));
  color: #fffdf0;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 3px 0 rgba(20, 56, 74, 0.42), 0 8px 24px rgba(20, 56, 74, 0.28);
  transform: translate(-50%, -10px);
  transition: opacity 260ms ease, transform 400ms ease;
}

.intro-panel.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.intro-panel h1 {
  color: inherit;
  font-size: clamp(2.7rem, 6.2vw, 5.5rem);
  letter-spacing: -0.055em;
  line-height: 0.92;
  text-shadow: inherit;
}

.intro-panel h1 span {
  display: block;
  color: #fff3b9;
  font-size: 0.72em;
  font-style: italic;
  letter-spacing: -0.045em;
}

.intro-panel p {
  margin: 20px 0 0;
  color: #fff;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: clamp(0.72rem, 1.6vw, 0.92rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.intro-panel kbd {
  color: var(--ink);
  text-shadow: none;
}

.panel::before {
  position: absolute;
  inset: 10px;
  border: 1px dashed rgba(20, 56, 74, 0.18);
  border-radius: 22px 18px 26px 17px;
  content: "";
  pointer-events: none;
}

.panel.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) rotate(-1deg) scale(1);
}

.eyebrow {
  position: relative;
  margin: 0 0 10px;
  color: var(--leaf);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: clamp(0.65rem, 1.2vw, 0.76rem);
  font-weight: 900;
  letter-spacing: 0.13em;
  line-height: 1.45;
  text-transform: uppercase;
}

h1,
h2 {
  position: relative;
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 900;
  letter-spacing: -0.065em;
}

h1 {
  font-size: clamp(3.5rem, 8vh, 5.65rem);
  line-height: 0.74;
  text-shadow: 3px 4px 0 rgba(246, 185, 59, 0.35);
}

h2 {
  font-size: clamp(2.3rem, 6vh, 3.9rem);
  line-height: 0.92;
  text-shadow: 2px 3px 0 rgba(246, 185, 59, 0.3);
}

.primary-button {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 22px;
  border: 2px solid #965916;
  border-radius: 17px 13px 18px 12px;
  background: var(--honey);
  box-shadow: 0 6px 0 var(--honey-dark);
  color: #3c2b1f;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.01em;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.primary-button:hover {
  filter: brightness(1.05);
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--honey-dark);
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--honey-dark);
}

.button-arrow {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 12px 10px 12px 9px;
  background: rgba(255, 255, 255, 0.58);
  font-size: 1.35rem;
}

.controls-hint {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 18px 0 0;
  color: var(--ink-soft);
  font-size: 0.73rem;
}

kbd {
  padding: 4px 7px;
  border: 1px solid rgba(20, 56, 74, 0.28);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.54);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.result-panel {
  left: 50%;
  text-align: center;
  transform: translate(-50%, calc(-50% + 24px)) rotate(1deg) scale(0.97);
}

.result-panel.is-visible {
  transform: translate(-50%, -50%) rotate(1deg) scale(1);
}

.result-scores {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  align-items: center;
  margin: 24px 0 22px;
  padding: 16px 0;
  border-block: 1px dashed rgba(20, 56, 74, 0.24);
}

.result-scores div {
  display: grid;
  gap: 3px;
}

.result-scores span {
  color: var(--ink-soft);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-scores strong {
  font-family: Georgia, serif;
  font-size: 2rem;
  line-height: 1;
}

.result-scores i {
  width: 1px;
  height: 42px;
  background: rgba(20, 56, 74, 0.22);
}

.pause-card {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  display: grid;
  min-width: 240px;
  gap: 7px;
  padding: 22px 28px;
  border: 2px solid rgba(20, 56, 74, 0.2);
  border-radius: 20px;
  background: rgba(255, 247, 214, 0.96);
  box-shadow: 0 10px 0 rgba(20, 56, 74, 0.17), 0 24px 60px var(--shadow);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -45%) scale(0.94);
  transition: opacity 180ms ease, transform 180ms ease;
}

.pause-card.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.pause-card span {
  font-family: Georgia, serif;
  font-size: 1.45rem;
  font-weight: 900;
}

.pause-card small {
  color: var(--ink-soft);
}

.rotate-note {
  display: none;
}

@media (max-width: 700px) {
  .intro-panel {
    top: max(72px, 10vh);
  }

  .intro-panel h1 {
    font-size: clamp(2.4rem, 12vw, 3.7rem);
  }

  .intro-panel p {
    margin-top: 16px;
  }

  .panel {
    top: auto;
    bottom: max(26px, calc(env(safe-area-inset-bottom) + 12px));
    left: 50%;
    padding: 26px 24px 20px;
    transform: translate(-50%, 24px) rotate(-1deg) scale(0.97);
  }

  .panel.is-visible {
    transform: translate(-50%, 0) rotate(-1deg) scale(1);
  }

  .result-panel,
  .result-panel.is-visible {
    top: 50%;
    bottom: auto;
  }

  .result-panel {
    transform: translate(-50%, calc(-50% + 24px)) rotate(1deg) scale(0.97);
  }

  .result-panel.is-visible {
    transform: translate(-50%, -50%) rotate(1deg) scale(1);
  }

  h1 {
    font-size: clamp(3.25rem, 15vw, 4.4rem);
  }

  .controls-hint {
    margin-top: 14px;
  }
}

@media (max-height: 620px) {
  .intro-panel {
    top: 50px;
  }

  .intro-panel h1 {
    font-size: clamp(2.2rem, 8.5vh, 3.5rem);
  }

  .panel {
    padding-top: 24px;
    padding-bottom: 18px;
  }

  h1 {
    font-size: 3.25rem;
  }

  .controls-hint {
    margin-top: 12px;
  }
}

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