@layer reset, base, components, responsive;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  * {
    margin: 0;
  }

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

  button {
    font: inherit;
  }
}

@layer base {
  :root {
    color-scheme: light;
    --sky: oklch(0.86 0.105 218);
    --sky-deep: oklch(0.77 0.13 221);
    --violet: oklch(0.445 0.206 279.1);
    --violet-dark: oklch(0.31 0.15 278);
    --violet-deep: oklch(0.21 0.055 278);
    --violet-soft: oklch(0.68 0.17 289);
    --screen: oklch(0.91 0.115 143);
    --screen-deep: oklch(0.83 0.13 143);
    --screen-ink: oklch(0.25 0.07 148);
    --berry: oklch(0.6 0.21 28);
    --berry-dark: oklch(0.43 0.17 25);
    --sun: oklch(0.86 0.17 89);
    --white: oklch(1 0 0);
    --off-white: oklch(0.97 0.012 280);
    --shadow: oklch(0.29 0.1 276 / 0.42);
    --focus: oklch(0.82 0.18 88);
    --z-decoration: 0;
    --z-content: 1;
    --z-overlay: 2;
  }

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

  body {
    min-height: 100dvh;
    overflow-x: hidden;
    color: var(--violet-deep);
    background:
      radial-gradient(circle at 12% 18%, oklch(0.92 0.14 90 / 0.85) 0 7rem, transparent 7.1rem),
      radial-gradient(circle at 91% 88%, oklch(0.68 0.17 289 / 0.7) 0 10rem, transparent 10.1rem),
      linear-gradient(145deg, var(--sky) 0%, oklch(0.82 0.13 227) 100%);
    font-family: ui-rounded, "Avenir Next", "Trebuchet MS", sans-serif;
    line-height: 1.45;
  }

  button {
    color: inherit;
  }

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

  kbd {
    display: inline-flex;
    min-width: 1.8em;
    min-height: 1.8em;
    align-items: center;
    justify-content: center;
    padding-inline: 0.45em;
    border: 2px solid var(--violet-deep);
    border-bottom-width: 4px;
    border-radius: 6px;
    color: var(--violet-deep);
    background: var(--white);
    font: 800 0.85em/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  }

  [hidden] {
    display: none !important;
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@layer components {
  .page-shell {
    position: relative;
    z-index: var(--z-content);
    display: flex;
    width: min(100% - 36px, 900px);
    min-height: 100dvh;
    margin-inline: auto;
    padding-block: 18px;
    align-items: center;
    justify-content: center;
    gap: 26px;
  }

  .toy-shape {
    position: fixed;
    z-index: var(--z-decoration);
    pointer-events: none;
  }

  .toy-shape-one {
    top: 8%;
    left: 7%;
    width: 54px;
    aspect-ratio: 1;
    border: 12px solid var(--berry);
    border-radius: 50%;
    transform: rotate(12deg);
  }

  .toy-shape-two {
    right: 6%;
    top: 9%;
    width: 78px;
    height: 28px;
    border-radius: 999px;
    background: var(--violet);
    transform: rotate(-22deg);
  }

  .toy-shape-three {
    bottom: 12%;
    left: 5%;
    width: 42px;
    height: 42px;
    background: var(--sun);
    clip-path: polygon(50% 0%, 61% 36%, 100% 38%, 68% 59%, 79% 100%, 50% 74%, 20% 100%, 31% 59%, 0 38%, 39% 36%);
  }

  .console {
    width: min(100%, 560px);
    flex: 0 1 560px;
    padding: 20px 22px 18px;
    border: 3px solid var(--violet-deep);
    border-radius: 28px;
    background: var(--violet);
    box-shadow: 0 12px 0 var(--shadow);
  }

  .console-header {
    display: flex;
    min-height: 52px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 2px 14px;
    color: var(--white);
  }

  .brand-lockup {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 11px;
  }

  .brand-lockup h1 {
    color: var(--white);
    font-size: 1.35rem;
    font-weight: 900;
    letter-spacing: -0.025em;
    line-height: 1.05;
    text-wrap: balance;
  }

  .brand-lockup p {
    margin-top: 4px;
    color: oklch(0.91 0.04 285);
    font-size: 0.74rem;
    font-weight: 700;
  }

  .brand-mark {
    position: relative;
    display: grid;
    width: 35px;
    height: 35px;
    flex: 0 0 auto;
    grid-template: repeat(3, 1fr) / repeat(3, 1fr);
    gap: 2px;
    transform: rotate(-4deg);
  }

  .brand-mark span {
    border-radius: 3px;
    background: var(--screen);
  }

  .brand-mark span:nth-child(1) {
    grid-area: 1 / 1;
  }

  .brand-mark span:nth-child(2) {
    grid-area: 1 / 2;
  }

  .brand-mark span:nth-child(3) {
    grid-area: 2 / 2;
  }

  .brand-mark span:nth-child(4) {
    grid-area: 2 / 3;
  }

  .sound-button {
    display: inline-flex;
    min-height: 40px;
    flex: 0 0 auto;
    align-items: center;
    gap: 7px;
    padding: 8px 11px;
    border: 2px solid var(--white);
    border-radius: 999px;
    color: var(--white);
    background: transparent;
    cursor: pointer;
    font-size: 0.74rem;
    font-weight: 850;
    transition: background-color 180ms ease, color 180ms ease, transform 180ms ease;
  }

  .sound-button:hover {
    color: var(--violet-deep);
    background: var(--white);
  }

  .sound-button:active {
    transform: translateY(2px);
  }

  .sound-button svg {
    width: 19px;
    height: 19px;
    overflow: visible;
    fill: currentColor;
  }

  .sound-button svg path:not(:first-child) {
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-width: 2;
  }

  .sound-button .sound-wave {
    display: none;
  }

  .sound-button[aria-pressed="true"] .sound-wave {
    display: block;
  }

  .sound-button[aria-pressed="true"] .sound-slash {
    display: none;
  }

  .screen-frame {
    padding: 10px;
    border: 3px solid var(--violet-deep);
    border-radius: 14px;
    background: var(--screen-deep);
    box-shadow: inset 0 0 0 3px oklch(0.72 0.11 144);
  }

  .score-bar {
    display: grid;
    min-height: 44px;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    padding: 0 8px 8px;
    color: var(--screen-ink);
  }

  .score-item {
    display: flex;
    align-items: baseline;
    gap: 7px;
  }

  .score-item-best {
    justify-content: flex-end;
  }

  .score-item span {
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .score-item output {
    font: 900 1.25rem/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-variant-numeric: tabular-nums;
  }

  .screen-status {
    display: flex;
    min-height: 27px;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border: 2px solid var(--screen-ink);
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 900;
  }

  .status-dot {
    width: 8px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--berry);
  }

  .screen-status[data-phase="playing"] .status-dot {
    background: var(--violet);
  }

  .screen-status[data-phase="paused"] .status-dot,
  .screen-status[data-phase="countdown"] .status-dot {
    border-radius: 2px;
    background: var(--sun);
  }

  .game-screen {
    position: relative;
    overflow: hidden;
    aspect-ratio: 1;
    border: 3px solid var(--screen-ink);
    border-radius: 8px;
    background: var(--screen);
  }

  #game-board {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
  }

  .game-overlay,
  .countdown {
    position: absolute;
    z-index: var(--z-overlay);
    inset: 0;
    display: grid;
    place-items: center;
  }

  .game-overlay {
    padding: 18px;
    color: var(--screen-ink);
    background: oklch(0.91 0.115 143 / 0.91);
  }

  .overlay-panel {
    display: flex;
    width: min(100%, 330px);
    align-items: center;
    flex-direction: column;
    text-align: center;
  }

  .overlay-panel h2 {
    margin-top: 10px;
    color: var(--screen-ink);
    font-size: 1.75rem;
    font-weight: 950;
    letter-spacing: -0.03em;
    line-height: 1.05;
    text-wrap: balance;
  }

  .overlay-panel > p:not(.keyboard-hint) {
    max-width: 28ch;
    margin-top: 8px;
    color: oklch(0.32 0.065 148);
    font-size: 0.95rem;
    font-weight: 750;
    text-wrap: pretty;
  }

  .berry-icon {
    position: relative;
    width: 50px;
    height: 48px;
    transform: rotate(-6deg);
  }

  .berry-fruit {
    position: absolute;
    right: 3px;
    bottom: 0;
    width: 40px;
    height: 37px;
    border: 3px solid var(--screen-ink);
    border-radius: 48% 52% 52% 48%;
    background: var(--berry);
  }

  .berry-fruit::before,
  .berry-fruit::after {
    position: absolute;
    top: 8px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--sun);
    content: "";
  }

  .berry-fruit::before {
    left: 9px;
  }

  .berry-fruit::after {
    right: 9px;
  }

  .berry-leaf {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 7px;
    width: 25px;
    height: 15px;
    border: 3px solid var(--screen-ink);
    border-radius: 80% 10% 80% 10%;
    background: var(--violet-soft);
    transform: rotate(20deg);
  }

  .primary-button {
    min-width: 156px;
    min-height: 48px;
    margin-top: 18px;
    padding: 10px 22px;
    border: 3px solid var(--violet-deep);
    border-radius: 999px;
    color: var(--white);
    background: var(--violet);
    box-shadow: 0 5px 0 var(--violet-deep);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 900;
    transition: filter 180ms ease, transform 180ms ease, box-shadow 180ms ease;
  }

  .primary-button:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 6px 0 var(--violet-deep);
  }

  .primary-button:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--violet-deep);
  }

  .keyboard-hint {
    margin-top: 13px;
    color: var(--screen-ink);
    font-size: 0.72rem;
    font-weight: 800;
  }

  .keyboard-hint kbd {
    min-height: 1.65em;
    border-color: var(--screen-ink);
    background: transparent;
  }

  .countdown {
    color: var(--screen-ink);
    background: oklch(0.91 0.115 143 / 0.83);
    font: 950 7rem/1 ui-rounded, "Avenir Next", sans-serif;
    text-shadow: 5px 5px 0 oklch(0.72 0.11 144);
  }

  .countdown.is-ticking {
    animation: count-in 540ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes count-in {
    from {
      opacity: 0;
      transform: scale(0.76);
    }
  }

  .screen-tip {
    display: flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 4px 0;
    color: var(--screen-ink);
    font-size: 0.74rem;
    font-weight: 800;
    text-align: center;
  }

  .screen-tip span {
    display: inline-grid;
    width: 24px;
    height: 19px;
    place-items: center;
    border-radius: 999px;
    color: var(--white);
    background: var(--violet);
    font-weight: 950;
  }

  .control-deck {
    display: flex;
    min-height: 116px;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 13px 18px 0;
  }

  .dpad-area {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .dpad-area > p {
    max-width: 10ch;
    color: var(--off-white);
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1.25;
  }

  .dpad {
    display: grid;
    width: 106px;
    height: 106px;
    flex: 0 0 auto;
    grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  }

  .dpad-button,
  .dpad-center {
    border: 0;
    color: var(--white);
    background: var(--violet-deep);
  }

  .dpad-button {
    cursor: pointer;
    font-size: 0.7rem;
    transition: background-color 150ms ease, transform 150ms ease;
  }

  .dpad-button:hover {
    color: var(--violet-deep);
    background: var(--sun);
  }

  .dpad-button:active {
    transform: scale(0.9);
  }

  .dpad-up {
    grid-area: 1 / 2;
    border-radius: 8px 8px 0 0;
  }

  .dpad-left {
    grid-area: 2 / 1;
    border-radius: 8px 0 0 8px;
  }

  .dpad-center {
    position: relative;
    grid-area: 2 / 2;
  }

  .dpad-center::after {
    position: absolute;
    inset: 9px;
    border-radius: 50%;
    background: oklch(0.29 0.07 278);
    content: "";
  }

  .dpad-right {
    grid-area: 2 / 3;
    border-radius: 0 8px 8px 0;
  }

  .dpad-down {
    grid-area: 3 / 2;
    border-radius: 0 0 8px 8px;
  }

  .action-area {
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 8px;
    transform: rotate(-6deg);
  }

  .pause-button {
    display: inline-flex;
    min-width: 104px;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 9px 16px;
    border: 3px solid var(--berry-dark);
    border-radius: 999px;
    color: var(--white);
    background: var(--berry);
    box-shadow: 0 5px 0 var(--berry-dark);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 900;
    transition: filter 180ms ease, transform 180ms ease, box-shadow 180ms ease;
  }

  .pause-button:hover:not(:disabled) {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 6px 0 var(--berry-dark);
  }

  .pause-button:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--berry-dark);
  }

  .pause-button:disabled {
    cursor: not-allowed;
    filter: grayscale(0.65);
    opacity: 0.62;
  }

  .pause-icon {
    display: flex;
    gap: 3px;
  }

  .pause-icon i {
    display: block;
    width: 4px;
    height: 14px;
    border-radius: 2px;
    background: currentColor;
  }

  .space-key {
    padding: 3px 13px 5px;
    border: 2px solid var(--off-white);
    border-bottom-width: 4px;
    border-radius: 6px;
    color: var(--off-white);
    font: 800 0.62rem/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  }

  .quick-guide {
    width: 250px;
    flex: 0 0 250px;
    padding: 22px;
    border: 3px solid var(--violet-deep);
    border-radius: 14px;
    background: var(--white);
    box-shadow: 8px 8px 0 var(--shadow);
    transform: rotate(1.5deg);
  }

  .quick-guide h2 {
    color: var(--violet);
    font-size: 1.45rem;
    font-weight: 950;
    letter-spacing: -0.03em;
  }

  .quick-guide ol {
    display: grid;
    margin-top: 16px;
    padding-left: 1.4rem;
    gap: 13px;
  }

  .quick-guide li {
    padding-left: 3px;
    color: var(--violet-deep);
    font-size: 0.88rem;
    font-weight: 650;
  }

  .quick-guide li::marker {
    color: var(--berry);
    font-weight: 950;
  }

  .quick-guide > p {
    margin-top: 18px;
    padding-top: 15px;
    border-top: 2px solid oklch(0.9 0.035 281);
    color: oklch(0.35 0.05 278);
    font-size: 0.78rem;
    font-weight: 750;
    line-height: 1.55;
  }
}

@layer responsive {
  @media (min-width: 600px) and (max-height: 850px) {
    .page-shell {
      width: min(100% - 28px, 800px);
      padding-block: 12px;
      gap: 22px;
    }

    .console {
      width: 470px;
      flex-basis: 470px;
      padding: 14px 16px 12px;
    }

    .console-header {
      min-height: 44px;
      padding-bottom: 10px;
    }

    .brand-mark {
      width: 31px;
      height: 31px;
    }

    .brand-lockup h1 {
      font-size: 1.18rem;
    }

    .screen-frame {
      padding: 8px;
    }

    .score-bar {
      min-height: 38px;
      padding-bottom: 6px;
    }

    .screen-tip {
      min-height: 31px;
      padding-top: 5px;
    }

    .control-deck {
      min-height: 88px;
      padding-top: 8px;
    }

    .dpad {
      width: 80px;
      height: 80px;
    }
  }

  @media (min-width: 600px) and (max-height: 650px) {
    .page-shell {
      width: min(100% - 20px, 700px);
      padding-block: 7px 10px;
      gap: 18px;
    }

    .console {
      width: 400px;
      flex-basis: 400px;
      padding: 9px 12px 8px;
      box-shadow: 0 7px 0 var(--shadow);
    }

    .console-header {
      min-height: 36px;
      padding-bottom: 7px;
    }

    .brand-lockup p,
    .sound-button span {
      display: none;
    }

    .sound-button {
      width: 38px;
      min-height: 36px;
      padding: 7px;
      justify-content: center;
    }

    .screen-frame {
      padding: 6px;
    }

    .score-bar {
      min-height: 31px;
      padding: 0 5px 4px;
    }

    .score-item output {
      font-size: 1rem;
    }

    .screen-status {
      min-height: 23px;
      padding-block: 2px;
    }

    .screen-tip {
      min-height: 24px;
      padding-top: 3px;
      font-size: 0.65rem;
    }

    .control-deck {
      min-height: 64px;
      padding: 4px 8px 0;
    }

    .dpad {
      width: 62px;
      height: 62px;
    }

    .dpad-area > p,
    .space-key {
      display: none;
    }

    .pause-button {
      min-width: 94px;
      min-height: 40px;
      padding-block: 6px;
    }

    .quick-guide {
      width: 220px;
      flex-basis: 220px;
      padding: 17px;
    }

    .quick-guide ol {
      margin-top: 10px;
      gap: 8px;
    }

    .quick-guide > p {
      margin-top: 11px;
      padding-top: 10px;
    }
  }

  @media (max-width: 880px) {
    .page-shell {
      width: min(100% - 28px, 560px);
      padding-block: 14px 26px;
      align-items: stretch;
      flex-direction: column;
    }

    .console {
      flex-basis: auto;
    }

    .quick-guide {
      width: 100%;
      flex-basis: auto;
      transform: none;
    }

    .quick-guide ol {
      grid-template-columns: repeat(3, 1fr);
      padding-left: 1.25rem;
    }
  }

  @media (max-width: 560px) {
    .toy-shape {
      display: none;
    }

    .page-shell {
      width: 100%;
      padding: 0;
    }

    .console {
      padding: 14px 12px 16px;
      border-width: 0;
      border-radius: 0;
      box-shadow: none;
    }

    .console-header {
      padding-inline: 4px;
    }

    .brand-lockup p,
    .sound-button span {
      display: none;
    }

    .sound-button {
      width: 42px;
      padding: 8px;
      justify-content: center;
    }

    .score-item {
      align-items: center;
      flex-direction: column;
      gap: 1px;
    }

    .score-item-best {
      justify-content: center;
    }

    .control-deck {
      padding-inline: 6px;
      gap: 12px;
    }

    .dpad-area {
      gap: 9px;
    }

    .dpad-area > p {
      font-size: 0.65rem;
    }

    .quick-guide {
      display: none;
    }
  }

  @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;
    }
  }
}
