:root {
  color-scheme: dark;
  font-family: Georgia, 'Times New Roman', serif;
  color: #fff0c7;
  background: #241007;
  --gold: #f7b743;
  --cream: #ffe4a4;
  --wood: #48200f;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
button { touch-action: manipulation; }
button:disabled { cursor: wait; opacity: .65; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.tavern {
  --scene-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  position: relative; isolation: isolate; display: grid; place-items: center; overflow: hidden;
  width: 100%; height: 100%; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tavern::before {
  content: ''; position: absolute; inset: -30px; z-index: -2;
  background: #3c1c0d url('/assets/menu-landscape.png') center / cover no-repeat;
  filter: blur(22px) brightness(.42); transform: scale(1.05);
}
.tavern::after {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(ellipse at center, transparent 30%, #160b0699);
}
.menu-scene {
  position: relative; width: 100%; max-width: calc(var(--scene-height) * 1672 / 941);
  aspect-ratio: 1672 / 941; flex: none; container-type: inline-size;
  box-shadow: 0 0 90px #140803b3;
}
.menu-art, .menu-art img { display: block; width: 100%; height: 100%; }
.menu-art { position: absolute; inset: 0; pointer-events: none; user-select: none; }
.menu-art img { object-fit: contain; }
.menu-video { display: none; position: absolute; inset: 0 0 auto; width: 100%; height: 57%; object-fit: cover; opacity: 0; pointer-events: none; }
.menu-top-overlay { display: none; position: absolute; top: 0; left: -2%; z-index: 2; width: 104%; max-width: none; height: auto; clip-path: inset(0 1.923077%); pointer-events: none; user-select: none; }
.menu-sound-art { display: none; position: absolute; inset: 0; overflow: hidden; border-radius: 50%; pointer-events: none; }
.menu-sound-art img { position: absolute; left: -605.932203%; top: -18.644068%; width: 722.033898%; height: 1564.40678%; max-width: none; }
@media (orientation: portrait) and (max-width: 700px) {
  .menu-video { display: block; }
  .menu-top-overlay { display: block; }
  .menu-video.is-playing { opacity: 1; }
  .menu-button--sound { z-index: 3; }
  .menu-sound-art { display: block; }
}
.ambience { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ambience canvas { display: block; width: 100%; height: 100%; }
.menu-actions { position: absolute; inset: 0; pointer-events: none; }
.menu-button {
  min-width: 44px; min-height: 44px;
  position: absolute; display: block; padding: 0; border: 0; cursor: pointer;
  background: transparent; pointer-events: auto; border-radius: 17% / 35%;
  transition: background-color .18s, box-shadow .18s, transform .18s;
  -webkit-touch-callout: none;
}
.menu-button--play { left: 54.9%; top: 38.3%; width: 41%; height: 17.4%; }
.menu-button--leaderboard { left: 56.5%; top: 59.3%; width: 38.5%; height: 12.3%; }
.menu-button--help { left: 56.5%; top: 75.1%; width: 38.5%; height: 12.3%; }
.menu-button--sound { right: 1.2%; top: 2.2%; width: 5.8%; height: 10.4%; border-radius: 50%; }
.menu-button:focus-visible { outline: 3px solid #fff3bd; outline-offset: 3px; box-shadow: 0 0 24px #ffc144bb; }
.menu-button:active { background-color: #ffca5729; transform: scale(.985); }
@media (hover: hover) {
  .menu-button:hover { background-color: #ffd77b16; box-shadow: 0 0 23px #ffaf3938, inset 0 0 20px #ffe9b424; }
}
.mute-mark {
  display: none; position: absolute; width: 66%; height: 5%; left: 17%; top: 48%;
  transform: rotate(-45deg); border-radius: 3px; background: #ffe9b1;
  box-shadow: 0 0 0 2px #71340c;
}
.menu-button--sound[aria-pressed='false'] .mute-mark { display: block; }

.tavern-dialog {
  width: min(90vw, 490px); max-height: min(90dvh, 760px); margin: auto;
  padding: 5px; overflow-y: auto; overscroll-behavior: contain;
  color: #ffedc4; border: 2px solid #d88c29; border-radius: 24px;
  background: linear-gradient(135deg, #ffdc7d, #a65014 35%, #f3b441 65%, #7c390e);
  box-shadow: 0 28px 100px #000b, 0 0 0 3px #3b170c, inset 0 0 0 1px #fff0a4;
}
.tavern-dialog::backdrop { background: #110803b5; backdrop-filter: blur(7px); }
.tavern-dialog[open] { animation: arrive .22s ease-out; }
.dialog-inner {
  position: relative; min-height: 100%; padding: 30px 30px 28px; text-align: center;
  border: 1px solid #a45e25; border-radius: 17px;
  background: repeating-linear-gradient(0deg, #24100615 0 2px, transparent 2px 9px),
    radial-gradient(ellipse at top, #713d20, #3d1b0d 70%);
}
.popup-skin, .instruction-art, .rank-medal { display: none; }
.close-button {
  position: absolute; top: 10px; right: 10px; width: 44px; height: 44px;
  display: grid; place-items: center; padding: 0; border: 1px solid #ce883d55;
  border-radius: 50%; background: #26100680; color: #ffe4a4;
  font: 28px/1 Georgia, serif; cursor: pointer;
}
.close-button:hover { background: #a45b2b55; }
button:focus-visible, input:focus-visible { outline: 2px solid #ffe1a0; outline-offset: 4px; }
.dialog-emblem { margin: 1px auto 13px; font-size: 43px; line-height: 1; color: var(--gold); text-shadow: 0 3px 0 #321204; }
.eyebrow { margin: 0 0 9px; font: 700 12px/1.4 Arial, sans-serif; letter-spacing: .24em; color: #eab965; }
h2 { margin: 0; font-size: clamp(26px, 7vw, 36px); color: var(--cream); text-shadow: 0 3px 2px #1d0908; }
.ornament { display: flex; align-items: center; gap: 12px; margin: 16px 0 22px; color: #f4b853; font-size: 12px; }
.ornament::before, .ornament::after { content: ''; height: 1px; flex: 1; background: linear-gradient(90deg, transparent, #d68c3c); }
.ornament::after { transform: rotate(180deg); }
.dialog-copy { margin: 0 0 23px; font: 16px/1.65 Georgia, serif; color: #ead0a8; }
.field-label { display: block; margin: 0 0 9px; text-align: left; font-size: 16px; color: var(--cream); }
.name-input {
  width: 100%; min-height: 52px; padding: 13px 15px; border: 1px solid #b97930;
  border-radius: 9px; background: #200e08b3; color: #fff0ca; font-size: 18px;
  box-shadow: inset 0 2px 7px #120703;
}
.name-input::placeholder { color: #b49a76; }
.form-error { min-height: 24px; margin: 9px 0; text-align: left; font: 14px/1.5 Arial, sans-serif; color: #ffd1a8; }
.gold-button {
  display: block; width: 100%; min-height: 52px; padding: 13px 20px;
  border: 1px solid #ffeaa0; border-radius: 10px; color: #452007;
  background: linear-gradient(#ffd66b, #f2a72c 65%, #d67d14);
  box-shadow: 0 4px 0 #813c0c, inset 0 0 0 2px #bb671d;
  font-weight: 700; font-size: 19px; text-shadow: 0 1px #ffe8a2; cursor: pointer;
}
.gold-button:hover { filter: brightness(1.1); }
.gold-button:active { transform: translateY(2px); box-shadow: 0 2px 0 #813c0c; }
.quiet-button { margin: 20px 0 0; padding: 10px; border: 0; color: #e3bd80; background: transparent; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; font-size: 16px; }
.empty-state { padding: 14px 0 19px; }
.empty-icon { width: 62px; height: 62px; margin-bottom: 14px; color: #d8a44e; }
.empty-state h3 { margin: 0 0 10px; color: #ffe1a0; font-size: 22px; }
.empty-state p { margin: 0; font-size: 16px; line-height: 1.6; color: #dec29c; }
.score-table-wrap { max-height: min(48dvh, 360px); overflow: auto; overscroll-behavior: contain; margin-bottom: 20px; }
.score-table { width: 100%; table-layout: fixed; border-collapse: collapse; text-align: left; font-size: 17px; }
.score-table th { padding: 10px 5px; color: #e9b650; font-size: 16px; }
.score-table th:first-child { width: 20%; text-align: center; }
.score-table th:nth-child(3) { width: 24%; text-align: center; }
.score-table th:last-child { width: 18%; text-align: right; }
.score-row { border-bottom: 1px solid #b779343b; }
.score-row td { padding: 14px 5px; }
.score-rank { width: 60px; text-align: center; color: #e9b650; font-weight: bold; }
.score-name { overflow-wrap: anywhere; }
.score-time { text-align: center; white-space: nowrap; font: 12px/1.25 Arial, sans-serif; font-variant-numeric: tabular-nums; }
.score-date, .score-clock { display: block; }
.score-date { opacity: .75; }
.score-clock { font-weight: bold; }
.score-value { text-align: right; color: #ffe2a0; font-variant-numeric: tabular-nums; }
.score-heading { display: grid; grid-template-columns: 20% minmax(0, 1fr) 24% 18%; gap: 0; padding: 10px 8px; border-radius: 7px; background: #ffffff0b; font-weight: bold; }
.score-heading span:first-child { text-align: center; }
.score-heading span:nth-child(2) { text-align: left; }
.score-heading span:nth-child(3) { text-align: center; }
.score-heading span:last-child { text-align: right; }
.help-list { display: grid; gap: 17px; margin: 0 0 26px; padding: 0; list-style: none; text-align: left; }
.help-list li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; }
.help-symbol { color: #f7bd59; font-size: 24px; text-align: center; }
.help-list h3 { margin: 0 0 4px; font-size: 18px; color: #ffe2a0; }
.help-list p { margin: 0; font-size: 16px; line-height: 1.5; color: #dec29c; }
.control-hint { margin: 0 0 24px; color: #be9c72; font: 14px/1.5 Arial, sans-serif; }
.status-message {
  position: fixed; z-index: 5; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%;
  transform: translate(-50%, 15px); opacity: 0; pointer-events: none;
  max-width: 90vw; width: max-content; margin: 0; padding: 12px 20px;
  border: 1px solid #cc934e; border-radius: 10px; color: #ffe6b3; background: #30170bed;
  font: 15px/1.5 Arial, sans-serif; transition: opacity .2s, transform .2s;
}
.status-message.is-visible { opacity: 1; transform: translate(-50%, 0); }
.noscript-message { position: fixed; inset: 40% 10% auto; padding: 24px; background: #32170f; text-align: center; }
@keyframes arrive { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }

@media (orientation: portrait) {
  .tavern::before { background-image: url('/assets/menu-portrait.png'); }
  .menu-scene { aspect-ratio: 852 / 1846; max-width: calc(var(--scene-height) * 852 / 1846); }
  .menu-button--play { left: 4.5%; top: 61.1%; width: 91%; height: 10.6%; }
  .menu-button--leaderboard { left: 8.1%; top: 75%; width: 84%; height: 7.7%; }
  .menu-button--help { left: 8.1%; top: 85.1%; width: 84%; height: 7.7%; }
  .menu-button--sound { right: 2.6%; top: 1.3%; width: 13.3%; height: 6.3%; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .tavern-dialog { max-height: 92dvh; width: min(90vw, 510px); border-radius: 18px; }
  .dialog-inner { padding: 20px 30px; }
  .dialog-emblem { display: none; }
  h2 { font-size: 27px; }
  .eyebrow { margin-bottom: 4px; }
  .ornament { margin: 10px 0 14px; }
  .dialog-copy { margin-bottom: 14px; }
  .help-list { gap: 10px; margin-bottom: 14px; }
  .empty-state { padding: 0 0 16px; }
  .empty-icon { width: 40px; height: 40px; margin-bottom: 8px; }
}

/* Phone popup skins. The original atlas supplies the frame and icon crops;
   an opaque parchment surface covers all of its example text and scores. */
@media (max-width: 600px), (max-width: 960px) and (max-height: 540px) {
  .illustrated-dialog {
    width: min(calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)), 460px);
    max-width: calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right));
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 0; border: 0; border-radius: 26px; background: transparent; color: #381a0b;
    box-shadow: none; color-scheme: light; scrollbar-width: thin; scrollbar-color: #9c6634 #f4dfbb;
  }
  .illustrated-dialog::backdrop { background: #160b0699; backdrop-filter: blur(5px); }
  .illustrated-dialog .dialog-inner {
    isolation: isolate; min-height: 430px; width: 100%;
    padding: max(58px, 15%) 7.7% 9%; border: 0; border-radius: 0; background: none;
  }
  .illustrated-dialog .popup-skin {
    display: block; position: absolute; inset: 0; z-index: -2; overflow: hidden;
    pointer-events: none; user-select: none;
  }
  .illustrated-dialog .popup-skin img {
    position: absolute; left: 0; top: -51.007557%; width: 200.305344%; height: 151.007557%; max-width: none;
  }
  .illustrated-dialog[data-view='help'] .popup-skin img { left: -100.305344%; }
  .illustrated-dialog .dialog-inner::after {
    content: ''; position: absolute; z-index: -1; inset: 5.4% 4.2% 4.7%; border-radius: 5% / 3%;
    background:
      repeating-linear-gradient(17deg, #9b652804 0 1px, transparent 1px 4px),
      repeating-linear-gradient(107deg, #fffbeb0a 0 2px, transparent 2px 6px),
      radial-gradient(ellipse at 48% 35%, #fff0d3 0%, #f7e3c0 55%, #e9c99a 100%);
    box-shadow: inset 0 0 15px #aa68292e;
  }
  .illustrated-dialog .close-button {
    z-index: 2; top: 5.2%; right: 5.5%; width: 44px; height: 44px;
    border: 2px solid #ffe8b5; color: #fff1d5; font-size: 34px; line-height: 1;
    background: radial-gradient(circle at 36% 26%, #975d2e, #55270d 80%);
    box-shadow: 0 0 0 2px #8a5128, 0 3px 5px #4a210c55, inset 0 0 0 2px #b17a43;
  }
  .illustrated-dialog .close-button:hover { filter: brightness(1.15); }
  .illustrated-dialog .close-glyph { transform: translateY(-2px); }
  .illustrated-dialog :is(.dialog-emblem, .eyebrow, .ornament) { display: none; }
  .illustrated-dialog h2 {
    margin: 0 0 23px; color: #371500; font-size: clamp(28px, 8.5vw, 40px);
    line-height: 1.15; font-weight: 800; text-shadow: 0 1px #fff6df;
  }
  .illustrated-dialog .dialog-copy { color: #684220; font-size: 16px; }
  .illustrated-dialog .gold-button {
    min-height: 46px; padding: 10px 18px; border: 2px solid #eab34e; border-radius: 12px;
    color: #fff0cc; background: repeating-linear-gradient(0deg, #a9621510 0 2px, transparent 2px 5px),
      linear-gradient(#7c3e16, #482009 65%, #5e2e0e);
    box-shadow: 0 2px 0 #421c09, 0 0 0 1px #7b430f, inset 0 0 0 2px #3e1a09;
    font-size: 22px; text-shadow: 0 2px #321306;
  }
  .illustrated-dialog .gold-button:focus-visible,
  .illustrated-dialog .close-button:focus-visible,
  .illustrated-dialog .score-table-wrap:focus-visible { outline: 3px solid #65320e; outline-offset: 3px; }
  .illustrated-dialog .panel-back { display: none; }
  .illustrated-dialog .score-table-wrap { max-height: min(48dvh, 330px); margin: 0; border-radius: 8px; }
  .illustrated-dialog .score-table { table-layout: fixed; border-collapse: separate; border-spacing: 0 7px; margin-top: -7px; color: #321708; font-weight: bold; }
  .illustrated-dialog .score-table thead { position: sticky; top: 0; z-index: 1; }
  .illustrated-dialog .score-table th {
    padding: 9px 7px; font: bold 17px/1.2 Georgia, serif; color: #3b210f; background: #e6caa1;
  }
  .illustrated-dialog .score-table th:first-child { width: 20%; border-radius: 8px 0 0 8px; }
  .illustrated-dialog .score-table th:last-child { width: 18%; border-radius: 0 8px 8px 0; }
  .illustrated-dialog .score-row { border: 0; }
  .illustrated-dialog .score-row td { height: 47px; padding: 5px 7px; border-bottom: 1px solid #bb8e5a88; }
  .illustrated-dialog .score-rank { width: auto; color: #321708; font-size: 22px; }
  .illustrated-dialog .score-name { color: #321708; font-size: clamp(16px, 4.6vw, 18px); line-height: 1.2; }
  .illustrated-dialog .score-value { color: #321708; font-size: clamp(16px, 4.6vw, 18px); white-space: nowrap; }
  .illustrated-dialog .score-row[data-rank='1'] td { background: linear-gradient(100deg, #f6d587, #ffe7af, #f2ce85); border-color: #cf9b3c; }
  .illustrated-dialog .score-row[data-rank='2'] td { background: linear-gradient(100deg, #d5c6b5, #f0e4d7, #d4c0aa); border-color: #c3ad93; }
  .illustrated-dialog .score-row[data-rank='3'] td { background: linear-gradient(100deg, #dfa86b, #f5c78e, #dfab71); border-color: #c58e52; }
  .illustrated-dialog .score-row:nth-child(-n+3) td:first-child { border-radius: 9px 0 0 9px; }
  .illustrated-dialog .score-row:nth-child(-n+3) td:last-child { border-radius: 0 9px 9px 0; }
  .illustrated-dialog .rank-number {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
  }
  .illustrated-dialog .rank-medal {
    display: block; position: relative; width: min(100%, 54px); aspect-ratio: 111 / 84;
    margin: auto; overflow: hidden; mix-blend-mode: darken; filter: brightness(1.16);
    clip-path: ellipse(49% 49% at 50% 50%);
    --crop-x: 74; --crop-w: 111; --crop-h: 84;
  }
  .rank-medal--1 { --crop-y: 671; }
  .rank-medal--2 { --crop-y: 765; }
  .rank-medal--3 { --crop-y: 856; }
  .illustrated-dialog .score-heading {
    grid-template-columns: 20% minmax(0, 1fr) 24% 18%; gap: 0; padding: 10px 8px; margin-bottom: 22px;
    background: #dec09688; border: 1px solid #c49e6e44; color: #3b210f; font-size: 17px;
  }
  .illustrated-dialog .empty-state { padding: 24px 0 28px; }
  .illustrated-dialog .empty-icon { color: #ac742c; }
  .illustrated-dialog .empty-state h3 { color: #4d2912; font-size: 22px; }
  .illustrated-dialog .empty-state p { color: #79532e; font-size: 16px; }
  .illustrated-dialog .help-list { display: grid; gap: 0; margin: 0 0 14px; }
  .illustrated-dialog .help-list li {
    grid-template-columns: 36% 1fr; gap: 12px; align-items: center; min-height: 70px; padding: 7px 0;
    border-bottom: 1px solid #b3875470; box-shadow: 0 1px #fff7e780;
  }
  .illustrated-dialog .help-list li:last-child { border: 0; box-shadow: none; }
  .illustrated-dialog .help-list h3 { margin: 0; font: 700 17px/1.25 Arial, sans-serif; color: #321a0c; }
  .illustrated-dialog .help-symbol, .illustrated-dialog .control-hint { display: none; }
  .illustrated-dialog .instruction-art {
    display: block; position: relative; width: 100%; aspect-ratio: var(--crop-w) / var(--crop-h);
    overflow: hidden; mix-blend-mode: darken; filter: brightness(1.18);
  }
  .instruction-art--move { --crop-x: 720; --crop-y: 585; --crop-w: 180; --crop-h: 90; }
  .instruction-art--pour { --crop-x: 718; --crop-y: 683; --crop-w: 175; --crop-h: 117; }
  .instruction-art--serve { --crop-x: 700; --crop-y: 812; --crop-w: 265; --crop-h: 110; }
  .instruction-art--time { --crop-x: 733; --crop-y: 938; --crop-w: 160; --crop-h: 112; }
  .illustrated-dialog :is(.instruction-art, .rank-medal) img {
    position: absolute; max-width: none; width: calc(1312 * 100% / var(--crop-w));
    height: calc(1199 * 100% / var(--crop-h));
    left: calc(-1 * var(--crop-x) * 100% / var(--crop-w));
    top: calc(-1 * var(--crop-y) * 100% / var(--crop-h));
  }
}
@media (max-width: 960px) and (max-height: 540px) and (orientation: landscape) {
  .illustrated-dialog { width: min(92vw, 540px); }
  .illustrated-dialog .dialog-inner { min-height: 0; padding: 50px 30px 24px; }
  .illustrated-dialog h2 { font-size: 30px; margin-bottom: 16px; }
  .illustrated-dialog .help-list { grid-template-columns: 1fr 1fr; gap: 5px 18px; }
  .illustrated-dialog .help-list li { grid-template-columns: 36% 1fr; min-height: 76px; padding: 5px 0; border-bottom: 1px solid #b3875470; box-shadow: none; }
  .illustrated-dialog .help-list h3 { font-size: 16px; }
  .illustrated-dialog .score-table-wrap { max-height: calc(100dvh - 155px); }
  .illustrated-dialog .empty-state { padding: 6px 0 12px; }
  .illustrated-dialog .score-heading { margin-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
