@font-face {
  font-family: Underdog;
  src: url('vendor/underdog/Underdog-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
:root {
  color-scheme: dark;
  --ink: #f6e2b8;
  --muted: #d1b78f;
  --gold: #c29450;
  --wine: #743e48;
  --pixel: Underdog, Georgia, serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", Arial, sans-serif;
  background-color: #24150f;
  /* The local room is supplied separately; wood and amber remain if absent. */
  background-image: linear-gradient(#1c100b65, #1c100bb3), url('assets/tavern-room-v1.webp'),
    radial-gradient(ellipse at 10% 20%, #a95a26, transparent 65%),
    repeating-linear-gradient(90deg, #291910 0 120px, #372116 122px 240px);
  background-position: center, center top, center, center;
  background-size: cover;
  background-attachment: fixed;
}
button, input, summary, select { font: inherit; }
button, summary { cursor: pointer; }
button {
  min-height: 46px;
  border: 3px solid #b78a4e;
  border-radius: 0;
  padding: 8px 17px;
  background: linear-gradient(#61432c, #39271e);
  color: #ffedc2;
  font: 600 16px/1.25 "Segoe UI", Arial, sans-serif;
  text-shadow: 2px 2px #241613;
  box-shadow: inset 2px 2px #ddb97950, inset -2px -2px #170e0b, 0 4px #170e0b;
  touch-action: manipulation;
}
button:hover:not(:disabled) { border-color: #f2ce83; }
button:active:not(:disabled) { translate: 0 2px; }
button:disabled { cursor: default; color: #b59c7e; border-color: #786044; }
button:focus-visible, summary:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #ffe2a0;
  outline-offset: 4px;
}
.masthead {
  position: relative;
  max-width: 1080px;
  margin: 16px auto 0;
  padding: 10px 26px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border: 3px solid #92663b;
  background: repeating-linear-gradient(0deg, #0000 0 7px, #130b0630 8px 9px), linear-gradient(90deg, #352117, #68432a 48%, #352117);
  box-shadow: inset 0 0 0 3px #21150e, inset 0 5px #b3894d, 0 6px 0 #180e09, 0 8px 24px #0009;
}
.masthead::before, .masthead::after {
  content: "";
  position: absolute;
  width: 5px; height: 5px;
  top: 14px;
  background: #b4935a;
  box-shadow: 1px 2px #160d09;
}
.masthead::before { left: 9px; }
.masthead::after { right: 9px; }
.brand { color: #f1ce91; font: 29px/1 var(--pixel); text-decoration: none; text-shadow: 2px 3px #21130f; }
.brand span { display: block; margin-top: 8px; font: 15px/1.4 "Segoe UI", sans-serif; color: #d8b888; }
.tavern-logo { flex: 0 0 64px; height: 64px; background: url('assets/red-moustache-v1.webp') center / contain no-repeat; }
main { max-width: 1120px; margin: auto; padding: 20px 20px 12px; }
.intro { margin: 0 0 14px; padding-left: 4px; text-shadow: 0 2px 3px #160c08, 0 0 10px #160c08; }
.sorting-title{font-size:32px;margin:0 0 12px}
.trisha-greeting{display:grid;grid-template-columns:76px minmax(0,1fr);align-items:start;gap:12px;margin-bottom:14px;padding:10px 12px;border:1px solid #ad8958;border-radius:14px;background:#39291feb;box-shadow:0 5px 18px #130e1740}
.trisha-greeting p{margin:0;font-size:14px;line-height:1.5}
.trisha-portrait{width:76px;height:76px;border:2px solid #be985f;border-radius:12px;background:#e9e0d3 url('assets/trisha-reference-v2.webp?v=greetings2') 11.3% 0/522% auto no-repeat;box-shadow:0 2px 6px #160e0a66}
@media(max-width:560px){.trisha-greeting{grid-template-columns:56px minmax(0,1fr);gap:10px}.trisha-portrait{width:56px;height:56px;border-radius:9px}.trisha-greeting p{font-size:13px}.sorting-title{font-size:28px}}
.eyebrow { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #e4bb79; margin: 0 0 5px; }
h1 { margin: 0; color: #ffe0a2; font: 44px/1.05 var(--pixel); }
.intro > .task-copy { margin: 4px 0 0; font: 23px/1.4 var(--pixel); color: #ffe3ad; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 22px; align-items: start; }
.play-area, aside { min-width: 0; }
.play-area {
  position: relative;
  padding: 14px;
  border: 3px solid #a3753e;
  background: linear-gradient(115deg, #49311fee, #281a14f5);
  box-shadow: inset 0 0 0 3px #1a100d, 0 0 0 3px #27170f, 0 9px 24px #0009, -16px -8px 70px #e8a13e22;
}
.table-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin: 0 0 14px; padding: 0 3px; }
.table-label { flex: 1 1 320px; font: 20px/1.4 var(--pixel); color: #f2d39d; }
#score { white-space: nowrap; font-size: 12px; color: #ffe3a4; padding: 3px 7px; background: #21160f; border: 1px solid #7c5934; }
.wood {
  position: relative;
  padding: 16px 16px 8px;
  border: 4px solid #352015;
  background: radial-gradient(ellipse at 25% 0, #e8ae5040, #0000 70%),
    repeating-linear-gradient(2deg, #0000 0 7px, #30190f20 8px 9px),
    repeating-linear-gradient(90deg, #704a2b 0, #805532 113px, #452c1c 115px, #8a5b33 119px, #6d462a 230px);
  box-shadow: inset 0 0 0 2px #bd8a4b, inset 0 0 25px #1a0d08, 0 3px #b28445;
}
/* Two decorative pixel candles sit on the table rim, outside card hit areas. */
.wood::before, .wood::after {
  content: ""; pointer-events: none; position: absolute; top: -11px;
  width: 6px; height: 10px; background: #fff0ab;
  box-shadow: 0 -4px #ffc761, 0 -7px 0 -1px #ffb04b, 0 10px #c4a46e, 0 15px #b08b57, -3px 20px #342017, 3px 20px #342017, 0 0 24px 9px #ffc55c55;
  animation: candle-glow 4s ease-in-out infinite alternate;
}
.wood::before { left: 4px; }
.wood::after { right: 4px; animation-delay: -2s; }
@keyframes candle-glow { to { filter: brightness(1.15); opacity: .85; } }
#board { position: relative; }
#canvas { position: absolute; inset: 0; pointer-events: none; }
#canvas canvas { display: block; }
#cards { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; scroll-margin-top:18px; }
#cards[data-pairs="10"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }
#cards[data-pairs="12"] { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.card {
  position: relative; aspect-ratio: 1.35;
  padding: 0; min-width: 0; min-height: 64px;
  border: 0; background: transparent; border-radius: 0;
  box-shadow: 3px 4px #24150b88;
}
.card:hover:not(:disabled) { background: #ffd2810a; }
.card:active:not(:disabled) { translate: none; }
.card:focus-visible { outline: 3px solid #ffe5a6; outline-offset: 2px; box-shadow: 0 0 0 5px #271b12; }
.card .name { position: absolute; bottom: 9px; left: 7px; right: 7px; color: #30271b; font: 11px/1.1 "Segoe UI", sans-serif; text-shadow: none; }
.table-bottom { display: flex; justify-content: space-between; gap: 8px; min-height: 22px; margin-top: 10px; color: #ffdfaa; font-size: 12px; text-shadow: 1px 1px #291a10; }
#moves-used { white-space: nowrap; font-variant-numeric: tabular-nums; }
#moves-used[data-warning="true"], #moves-left[data-warning="true"] { color: #ff9393; font-weight: 700; }
.controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.primary { background: linear-gradient(#8d4852, #532c37); border-color: #dbb572; }
.field-control { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.field-control select { max-width: 100%; min-height: 44px; padding: 6px; color: var(--ink); background: #21160f; border: 2px solid #a3753e; }
.field-control p { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12px; }
#moves-left { color: #ffe3a4; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; padding: 7px 9px; border: 1px solid #a3753e; background: #21160f; }
.supplies { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; padding: 7px 9px; border: 1px solid #785633; background: #241a12; }
.supplies h2 { margin: 0; font-size: 18px; }
.supplies p { margin: 0; color: var(--muted); font-size: 12px; }
.supply-slots { display: flex; gap: 6px; }
.supply-slots span { width: 32px; height: 32px; border: 2px solid #85633d; background: #19120e; box-shadow: inset 2px 2px #0f0b08; }
.feedback { min-height: 38px; margin: 12px 2px 8px; font-size: 13px; color: #ead1ab; }
.settings { padding: 10px 12px; border: 2px solid #876138; background: #211811; box-shadow: inset 0 0 0 2px #100c09; }
summary { min-height: 30px; padding: 3px 0; font: 21px/1.2 var(--pixel); color: #f4d095; }
summary::marker { color: #cf9b53; }
summary span { float: right; margin-top: 4px; color: #c9ae88; font: 11px/1.5 "Segoe UI", sans-serif; }
aside { border: 3px solid #947045; padding: 12px; background: linear-gradient(100deg, #34271df5, #231a14f5); box-shadow: inset 0 0 0 3px #17100b, 0 6px 20px #0009; }
.dragon-panel { text-align: center; border-bottom: 2px solid #7d5936; padding: 0 0 10px; }
.dragon-panel .eyebrow { color: #dab577; margin-bottom: 8px; }
.portrait-frame { width: 156px; margin: auto; padding: 5px; background: #21180e; border: 3px solid #d0a35d; box-shadow: 0 0 0 2px #130e0b, inset 0 0 0 2px #684a2a, 0 3px 12px #0008; }
.portrait-crop { width: 140px; height: 140px; overflow: hidden; position: relative; background: #bcb6a5; }
.portrait-crop .dragon { display: block; position: absolute; width: 500px; height: auto; max-width: none; left: -20px; top: -20px; }
h2 { margin: 8px 0 4px; color: #f1ce8d; font: 25px/1 var(--pixel); }
h2 small { display: block; margin-top: 7px; color: #d4b68a; font: 14px/1.4 "Segoe UI", sans-serif; }
.dragon-panel > p:last-child { margin: 5px 0 0; font-size: 12px; color: var(--muted); }
.instructions { padding: 8px 2px; }
.instructions h2 { font-size: 23px; }
.instructions ol { padding-left: 18px; margin: 8px 0; font-size: 14px; }
.instructions li { padding-left: 2px; margin-bottom: 5px; }
.instructions li::marker { color: #e3af61; }
.instructions p, .settings p, .preview-note { color: var(--muted); font-size: 11px; line-height: 1.45; }
.instructions p { margin: 8px 0; }
.settings { padding: 7px 9px; }
.settings summary { font-size: 20px; }
.settings label { display: flex; justify-content: space-between; gap: 4px; margin-top: 10px; font-size: 12px; }
.settings output { white-space: nowrap; color: #f9d69c; font-variant-numeric: tabular-nums; }
.settings input { display: block; width: 100%; min-height: 28px; accent-color: #d6a350; }
.settings p { margin: 2px 0 8px; }
.preview-note { margin: 10px 2px 0; }
footer { max-width: 1080px; margin: 0 auto; padding: 10px 4px 18px; font: 19px/1.3 var(--pixel); color: #dfb876; text-shadow: 1px 2px #160c08; }
footer span { float: right; font: 12px/1.5 "Segoe UI", sans-serif; color: #d2b88d; }
noscript { display: block; padding: 12px; background: #321d16; }
@media (max-width: 1100px) {
  .masthead { margin: 12px 20px 0; }
  footer { margin: 0 20px; }
  .layout { gap: 16px; grid-template-columns: minmax(0, 1fr) 240px; }
  .card { aspect-ratio: 1.1; }
  #cards { gap: 9px; }
  .wood { padding: 12px 10px 6px; }
  .play-area { padding: 10px; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .card { aspect-ratio: 1.15; }
  aside { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .dragon-panel { border-bottom: 0; }
  .settings, .preview-note { grid-column: 1 / -1; }
  .instructions { padding: 0; }
  main { padding-top: 16px; }
}
@media (max-width: 460px) {
  .masthead { margin: 8px 10px 0; padding: 10px 16px; gap: 8px; }
  .brand { font-size: 24px; }
  .brand span { font-size: 13px; }
  .tavern-logo { flex-basis: 48px; height: 48px; }
  main { padding: 16px 10px 10px; }
  h1 { font-size: 36px; }
  .intro > .task-copy { font-size: 20px; }
  .eyebrow { font-size: 9px; }
  .play-area { padding: 8px; border-width: 2px; }
  .table-label { font-size: 17px; }
  #score { font-size: 10px; padding: 3px 4px; }
  #cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  #cards[data-pairs="8"], #cards[data-pairs="10"], #cards[data-pairs="12"] { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .card { aspect-ratio: .85; min-height: 88px; }
  #cards[data-pairs="10"] .card,#cards[data-pairs="12"] .card{aspect-ratio:1.1;min-height:60px}
  .wood { padding: 11px 7px 6px; border-width: 3px; }
  .table-bottom { font-size: 10px; }
  .controls { gap: 8px; }
  .controls button { padding: 9px 10px; font-size: 20px; }
  .card .name { font-size: 9px; bottom: 2px; left: 2px; right: 2px; overflow-wrap: anywhere; }
  .feedback { font-size: 12px; }
  summary span { float: none; display: block; margin-left: 16px; }
  aside { grid-template-columns: 1fr; }
  .dragon-panel { border-bottom: 2px solid #7d5936; }
  footer { margin: 0 12px; }
}
#result { width: min(440px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; padding: 24px; border: 3px solid #c29450; border-radius: 12px; color: var(--ink); background: linear-gradient(135deg, #503323, #241912); box-shadow: 0 12px 60px #000a; text-align: center; }
#result::backdrop { background: #150d09bb; }
#result h2 { font-size: 30px; line-height: 1.2; }
#result .controls { justify-content: center; }
#result-art { display: flex; justify-content: center; gap: 8px; }
#result-art img { image-rendering: pixelated; animation: harvest-sway 650ms ease-in-out 3 alternate; }
#result-art img:nth-child(2) { animation-delay: 100ms; }
#result-art img:nth-child(3) { animation-delay: 200ms; }
@keyframes harvest-sway { from { transform: rotate(-7deg); } to { transform: rotate(7deg) translateY(-3px); filter: brightness(1.15); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
