@layer base, shell, player, guide, responsive;

@layer base {
  :root {
    color-scheme: dark;
    --bg: #101722;
    --panel: #1a2535;
    --ink: #f4f7fb;
    --muted: #b8c5d6;
    --gold: #f9cc48;
    --focus: #7ad8ff;
    --line: #33445b;
    --dark: #0b111b;
    --heading: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
    --body: Inter, system-ui, sans-serif;
    --space: 24px;
    --radius: 12px;
  }

  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 400 1rem/1.6 var(--body);
  }

  h1, h2, h3, p, ol, ul, dl, dd { margin: 0; }
  p { color: var(--muted); }
  button, summary { cursor: pointer; }
  button { font: inherit; }
  a { color: inherit; text-underline-offset: 4px; }
  a:hover { color: var(--gold); }
  :focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
  [id] { scroll-margin-top: 18px; }

  h1, h2 { font-family: var(--heading); font-weight: 700; }
  h2 { font-size: clamp(2rem, 4.3vw, 2.9rem); line-height: 1.04; }
  h3 { font-size: 1.03rem; line-height: 1.4; }
  .shell { width: min(calc(100% - 2 * var(--space)), 1120px); margin-inline: auto; }
  .skip-link {
    position: absolute;
    z-index: 10;
    inset: 8px auto auto 8px;
    padding: 10px 14px;
    transform: translateY(-150%);
    background: var(--gold);
    color: var(--bg);
  }
  .skip-link:focus { transform: none; }
}

@layer shell {
  .site-header {
    background: var(--dark);
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 2;
  }

  .header-inner {
    min-height: 52px;
    display: flex;
    align-items: center;
    gap: 22px;
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-height: 44px;
    font-family: var(--heading);
    font-size: 1.38rem;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
  }
  .brand img { display: block; border-radius: 6px; }

  .primary-nav {
    display: flex;
    align-items: center;
    margin-left: auto;
    gap: 17px;
    font-size: .875rem;
    font-weight: 600;
  }
  .primary-nav a { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
  .primary-nav .play-link { padding-inline: 12px; white-space: nowrap; }
  .language-menu { position: relative; font-size: .82rem; }
  .language-menu summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    gap: 9px;
    white-space: nowrap;
    color: var(--muted);
    list-style: none;
  }
  .language-menu summary::-webkit-details-marker { display: none; }
  .language-menu summary:hover { color: var(--ink); }
  .language-menu summary::after {
    content: "";
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border: solid currentColor;
    border-width: 0 1px 1px 0;
    transform: rotate(45deg);
    margin-bottom: 3px;
  }
  .language-menu[open] summary::after { transform: rotate(225deg); margin-bottom: -3px; }
  .language-options {
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    width: max-content;
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    list-style: none;
    box-shadow: 0 10px 24px #0006;
  }
  .language-options a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 5px;
    text-decoration: none;
  }
  .language-options a[aria-current], .language-options a:hover { background: var(--bg); color: var(--gold); }

  .button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 44px;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 7px;
    font-size: .875rem;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
  }
  .button-primary { background: var(--gold); color: var(--bg); }
  .button-primary:hover { background: #ffe088; color: var(--bg); }
  .button-soft { background: var(--panel); border-color: var(--line); color: var(--ink); }
  .button-soft:hover { color: var(--gold); border-color: var(--gold); }

  .hero { padding-block: 26px 19px; }
  .hero h1 {
    max-width: 1040px;
    font-size: clamp(2.55rem, 6.15vw, 5.2rem);
    letter-spacing: -.015em;
    line-height: .98;
    text-wrap: balance;
  }
  .hero h1 span { color: var(--gold); }
  .hero p { margin-top: 11px; font-size: clamp(.93rem, 1.6vw, 1.1rem); }
  .site-footer {
    padding-block: 28px;
    border-top: 1px solid var(--line);
    background: var(--dark);
  }
  .footer-inner { display: flex; justify-content: space-between; align-items: start; gap: 20px 48px; }
  .footer-inner p { max-width: 440px; margin-top: 3px; font-size: .86rem; }
  .footer-links { display: flex; flex-wrap: wrap; gap: 0 19px; }
  .footer-links a { display: inline-flex; align-items: center; min-height: 44px; font-size: .88rem; }
}

@layer player {
  .player {
    overflow: clip;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--dark);
    box-shadow: 0 14px 32px #0004;
  }
  .player-toolbar, .player-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0 16px;
    padding: 4px 14px;
    background: var(--panel);
  }
  .player-name {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding-block: 6px;
    line-height: 1.3;
    font-size: .875rem;
    font-weight: 700;
  }
  .status-light {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: var(--gold);
  }
  .player-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0 14px; }
  .player-actions a, .player-status a {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 44px;
    font-size: .83rem;
    font-weight: 600;
    text-decoration: none;
  }
  .player-actions .button-soft { background: var(--dark); padding-inline: 10px; }
  .fullscreen-mark {
    width: 13px;
    height: 13px;
    background:
      linear-gradient(currentColor, currentColor) left top / 5px 1px,
      linear-gradient(currentColor, currentColor) left top / 1px 5px,
      linear-gradient(currentColor, currentColor) right top / 5px 1px,
      linear-gradient(currentColor, currentColor) right top / 1px 5px,
      linear-gradient(currentColor, currentColor) left bottom / 5px 1px,
      linear-gradient(currentColor, currentColor) left bottom / 1px 5px,
      linear-gradient(currentColor, currentColor) right bottom / 5px 1px,
      linear-gradient(currentColor, currentColor) right bottom / 1px 5px;
    background-repeat: no-repeat;
  }
  .game-viewport {
    position: relative;
    isolation: isolate;
    width: 100%;
    aspect-ratio: 16 / 9;
    min-height: 240px;
  }
  .game-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    background: radial-gradient(ellipse at 50% 60%, #1a2535, #0b111b 70%);
    color: var(--muted);
    font-size: .95rem;
  }
  .game-placeholder img { border-radius: 14px; }
  .game-viewport iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
  .game-viewport iframe:focus-visible { outline-offset: -3px; }
  .player-status { min-height: 44px; padding-block: 0; border-top: 1px solid var(--line); }
  .player-status p { padding-block: 7px; font-size: .82rem; line-height: 1.4; }
  .player-status a { color: var(--gold); flex-shrink: 0; }
  .no-script { padding-top: 8px; }

  .player:fullscreen, .player.is-expanded {
    display: flex;
    flex-direction: column;
    border: 0;
    border-radius: 0;
    width: 100%;
    height: 100%;
  }
  .player.is-expanded { position: fixed; inset: 0; z-index: 20; height: 100dvh; }
  .expanded-player { overflow: hidden; }
  .player:fullscreen .game-viewport, .player.is-expanded .game-viewport {
    flex: 1;
    min-height: 0;
    aspect-ratio: auto;
  }
}

@layer guide {
  .guide { max-width: 760px; margin-block: 38px 64px; }
  .guide-section + .guide-section { border-top: 1px solid var(--line); margin-top: 36px; padding-top: 32px; }
  .guide-section > p, .legal p { margin-top: 13px; }
  .text-link { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--gold); font-weight: 600; }
  .guide-section > .text-link { margin-top: 11px; }

  .game-screenshot { margin: 20px 0 0; }
  .game-screenshot img {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .game-screenshot figcaption { margin-top: 8px; color: var(--muted); font-size: .875rem; }

  .start-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 0;
    margin-top: 16px;
    list-style: none;
    counter-reset: step;
  }
  .start-steps li {
    display: flex;
    align-items: start;
    gap: 10px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    counter-increment: step;
  }
  .start-steps li::before {
    content: counter(step);
    display: grid;
    place-items: center;
    flex: 0 0 25px;
    height: 25px;
    border: 1px solid #8f7540;
    border-radius: 6px;
    color: var(--gold);
    font-size: .83rem;
    font-weight: 700;
  }
  .start-steps p, .device-notes p { margin-top: 5px; font-size: .93rem; }

  .control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
  .control-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 15px 3px;
  }
  .control-card:last-child { grid-column: 1 / -1; }
  .control-card h3 { color: var(--gold); margin-bottom: 6px; }
  .control-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px 14px;
    padding-block: 9px;
    border-top: 1px solid var(--line);
    font-size: .91rem;
  }
  .control-row dd { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
  kbd {
    display: inline-block;
    background: var(--dark);
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 0 6px;
    color: var(--ink);
    white-space: nowrap;
    font: 600 .79rem/1.65 var(--body);
  }
  .device-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 23px; margin-top: 18px; }

  .accordion { border-top: 1px solid var(--line); margin-top: 15px; }
  .accordion details { border-bottom: 1px solid var(--line); }
  .accordion summary {
    min-height: 49px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    list-style: none;
    padding-block: 11px;
    font-weight: 600;
    line-height: 1.35;
  }
  .accordion summary::-webkit-details-marker { display: none; }
  .accordion summary::after { content: "+"; flex: 0 0 16px; font-size: 1.2rem; text-align: center; color: var(--gold); }
  .accordion details[open] summary::after { content: "−"; }
  .accordion summary:hover, .accordion details[open] summary { color: var(--gold); }
  .accordion p { margin: 0 26px 14px 0; }
  .help-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 16px; margin-top: 14px; }

  .legal { max-width: 760px; margin-block: 50px 65px; }
  .legal h1 { font-size: clamp(2.8rem, 7vw, 4.8rem); line-height: 1; }
  .legal h2 { margin-top: 28px; font-size: 1.9rem; }
  .legal a { color: var(--gold); overflow-wrap: anywhere; }
  .legal .updated { margin-top: 6px; font-size: .9rem; }
}

@layer responsive {
  @media (max-width: 720px) {
    :root { --space: 16px; }
    .header-inner { min-height: 50px; gap: 9px; }
    .brand { font-size: 1.24rem; gap: 5px; }
    .brand img { width: 23px; height: 23px; }
    .primary-nav { gap: 0; }
    .primary-nav .wide-link { display: none; }
    .primary-nav .play-link { padding-inline: 8px; font-size: .78rem; }
    .language-menu { min-width: 0; }
    .language-menu summary { gap: 5px; font-size: .76rem; line-height: 1.2; white-space: normal; }
    .hero { padding-block: 20px 15px; }
    .hero p { margin-top: 10px; }
    .footer-inner { flex-direction: column; gap: 9px; }
    .start-steps, .control-grid, .device-notes { grid-template-columns: 1fr; }
    .guide { margin-block: 29px 43px; }
    .guide-section + .guide-section { padding-top: 24px; margin-top: 27px; }
    .player-toolbar, .player-status { padding-inline: 10px; }
    .player-toolbar { flex-wrap: wrap; }
    .player-actions { gap: 0 8px; }
    .player-actions a, .player-actions .button { font-size: .75rem; }
    .player-actions .button { padding-inline: 7px; }
    .player-name { flex-basis: 100%; }
  }

  @media (max-width: 380px) {
    .header-inner { gap: 6px; }
    .brand { font-size: 1.12rem; }
    .language-menu summary { font-size: .70rem; }
  }

  @media (max-height: 480px) and (orientation: landscape) {
    .player:fullscreen .player-name, .player.is-expanded .player-name { flex-basis: auto; }
    .player:fullscreen .player-status, .player.is-expanded .player-status { display: none; }
  }
}
