:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #fff0d4;
  background: #101d2d;
  --gold: #ffd382;
  --muted: #b9c5cb;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, canvas:focus-visible { outline: 3px solid #fff; outline-offset: -3px; }
button:disabled { cursor: default; }
button { color: #fff0d4; background: #263c4c; border: 1px solid #5b7180; border-radius: 12px; min-height: 44px; padding: 8px 14px; }
button:hover:not(:disabled) { filter: brightness(1.14); }
button:active:not(:disabled) { transform: translateY(2px); }
button.primary { background: var(--gold); border-color: #ffeac2; color: #352c23; font-weight: 800; }
button:disabled { opacity: .45; }
#app { width: 100%; height: 100%; display: grid; grid-template-rows: 64px minmax(130px, 1fr) minmax(210px, 42%); position: relative; max-width: 1200px; margin: auto; background: #152b3a; }
header { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; z-index: 2; gap: 6px; background: #142637; border-bottom: 1px solid #42525c; }
header strong { font-family: Georgia, serif; font-size: clamp(16px, 4vw, 22px); display: block; }
header span { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; }
nav { display: flex; gap: 5px; }
nav button { padding: 0; width: 44px; font-size: 20px; }
#table { position: relative; min-height: 0; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#opponents { position: absolute; left: 8px; right: 8px; top: 9px; display: flex; justify-content: space-between; pointer-events: none; gap: 6px; }
.opponent { flex: 1; max-width: 150px; padding: 6px 4px; border: 1px solid #53656c; border-radius: 12px; text-align: center; background: #152737e8; font-size: 12px; transition: border-color .2s, background .2s; }
.opponent.active { border-color: #ffe1a1; background: #50503c; box-shadow: 0 0 14px #ffcf6844; }
.opponent strong { display: block; font-size: 14px; }
.opponent small { display: block; margin-top: 3px; color: #b9c5cb; font-size: 10px; }
.opponent .count { color: #ffe1a1; }
#match { position: absolute; left: 12px; right: 12px; bottom: 10px; text-align: center; font-size: 13px; pointer-events: none; text-shadow: 0 1px 4px #000; }
#match-color { border-radius: 8px; padding: 3px 8px; margin-right: 6px; color: #172331; font-weight: 800; }
#direction { display: block; color: #c8d8db; font-size: 10px; margin-top: 5px; }
#controls { min-height: 0; display: grid; grid-template-rows: auto 38px minmax(60px, 1fr) 46px 18px; padding: 9px 10px 4px; gap: 4px; background: #142637; border-top: 1px solid #4b606a; }
#turn-line { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
#turn { color: #ffe1a1; font-size: 15px; }
#hand-count { font-size: 11px; color: var(--muted); }
#message { margin: 0; font-size: 12px; line-height: 17px; overflow: auto; }
#hand { display: grid; grid-template-columns: repeat(auto-fill, minmax(53px, 1fr)); align-content: start; overflow-y: auto; gap: 7px; padding: 4px 3px 8px; scrollbar-width: thin; overscroll-behavior: contain; }
.card { min-width: 0; min-height: 72px; position: relative; padding: 4px 1px; border: 2px solid #687477; border-radius: 9px; color: #142334; background: var(--card); box-shadow: inset 0 0 0 3px #ffffff30, 0 3px 0 #0005; opacity: .64; }
.card:not(:disabled) { opacity: 1; border-color: #fff4cb; box-shadow: 0 0 9px #ffd27a55, inset 0 0 0 3px #fff4; }
.card:disabled { opacity: .52; }
.card .symbol { display: block; font-size: 27px; line-height: 31px; font-weight: 900; font-family: Georgia, serif; }
.card .label { font-size: 10px; font-weight: 800; display: block; }
.card .key { position: absolute; left: 3px; top: 2px; font-size: 9px; font-weight: 800; }
.card.new { animation: arrive .3s ease-out; }
.card.wish { background: linear-gradient(135deg,#f5a6a8,#f4d580 35%,#8ed9b0 65%,#9bc7ef); }
@keyframes arrive { from { transform: translateY(-12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
#actions { display: flex; gap: 8px; }
#draw { flex: 1; }
#sort { font-size: 12px; }
#hint { margin: 0; text-align: center; font-size: 9px; line-height: 14px; color: #aabec8; }
.overlay { position: absolute; inset: 64px 0 0; z-index: 5; background: #0c192acb; backdrop-filter: blur(5px); display: flex; overflow-y: auto; padding: 16px; }
.overlay[hidden] { display: none; }
.panel { width: min(100%, 440px); margin: auto; border: 1px solid #8c7959; border-radius: 22px; background: linear-gradient(160deg, #2d4350, #182c3c); padding: 22px; box-shadow: 0 15px 60px #0007; }
.panel h1, .panel h2 { font-family: Georgia, serif; font-weight: 500; margin: 5px 0 12px; color: #ffe1a1; font-size: clamp(26px, 7vw, 39px); }
.panel .eyebrow { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: #b4d6d4; margin: 0; }
.panel p { font-size: 14px; line-height: 1.5; }
.panel .subtle { color: #afc2ca; font-size: 11px; }
.panel button { width: 100%; margin-top: 8px; }
.panel .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel .pair button { font-size: 13px; }
.panel ul { padding-left: 18px; font-size: 13px; line-height: 1.5; }
.panel li { margin-bottom: 6px; }
.panel .colors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel .colors button { color: #182c3c; font-weight: 800; min-height: 64px; }
.score-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; font-size: 14px; }
.score-row b { color: #ffd78c; }
@media (min-width: 700px) and (min-height: 550px) {
  #app { grid-template-rows: 70px minmax(220px, 1fr) 260px; }
  .overlay { top: 70px; }
  #controls { padding: 12px 20px 6px; }
  #hand { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
  .card { min-height: 86px; }
  #opponents { left: 8%; right: 8%; top: 15px; }
  .opponent { padding: 10px; }
}
@media (max-height: 500px) and (min-width: 540px) {
  #app { grid-template-columns: 48% 52%; grid-template-rows: 54px minmax(0,1fr); }
  header { grid-column: 1 / 3; padding: 5px 10px; }
  #table { grid-column: 1; grid-row: 2; }
  #controls { grid-column: 2; grid-row: 2; border-top: 0; border-left: 1px solid #4b606a; grid-template-rows: auto 38px minmax(50px,1fr) 44px 16px; padding: 8px; }
  .overlay { top: 54px; padding: 10px; }
  .panel { padding: 16px; }
  .panel h1, .panel h2 { font-size: 28px; }
  .panel p { margin: 8px 0; }
  .card { min-height: 68px; }
  .opponent { font-size: 11px; }
  .opponent small { display: none; }
  #match { bottom: 8px; font-size: 12px; }
}
@media (max-width: 350px) {
  header { padding: 6px; }
  nav { gap: 2px; }
  nav button { width: 40px; }
  header span { font-size: 8px; }
  #hand { grid-template-columns: repeat(auto-fill,minmax(48px,1fr)); gap: 5px; }
  .panel { padding: 15px; }
  #hint { font-size: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
