/* The Goblin's Treasure — a full-bleed cavern with glass panels floating over it. */
:root {
  color-scheme: dark;
  --bg: #071319;
  --panel: rgba(9, 24, 30, .68);
  --panel-solid: #0e2229;
  --line: rgba(160, 220, 205, .16);
  --text: #f3eedb;
  --muted: #a5bcb2;
  --gold: #f0c265;
  --gold-deep: #c98a2b;
  --teal: #4fe0c4;
  --violet: #b58cff;
  --serif: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --sans: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--sans); overflow-x: hidden;
}
p { color: var(--muted); }
button, select, input { font: inherit; }
button {
  cursor: pointer; color: var(--text); padding: 10px 16px; border-radius: 10px;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--line);
  transition: background .2s, transform .2s, border-color .2s, box-shadow .2s;
}
button:hover:enabled { background: rgba(255, 255, 255, .12); border-color: rgba(240, 194, 101, .5); transform: translateY(-1px); }
button:disabled { opacity: .38; cursor: default; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 3px;
}
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 2.4px; color: var(--gold); }

/* ------------------------------------------------------------ header */
header {
  position: relative; z-index: 5; height: 64px; padding: 0 clamp(14px, 2.6vw, 40px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(#050d11, #071319); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; }
.sigil { width: 22px; height: 28px; filter: drop-shadow(0 0 8px #f0a83a99); }
.brand-text b { display: block; font: 700 15px/1.1 var(--serif); letter-spacing: 3px; }
.brand-text small { display: block; margin-top: 3px; font-size: 11px; letter-spacing: 4px; color: var(--muted); }
.header-actions { display: flex; gap: 10px; }
header button { font-size: 14px; padding: 8px 14px; background: transparent; }

/* ------------------------------------------------------------- arena */
main { padding: 0; }
.game-layout { display: block; }
.arena { position: relative; height: calc(100vh - 64px); height: calc(100dvh - 64px); min-height: 560px; overflow: hidden; background: var(--bg); }
#scene { position: absolute; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; }
.vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse at 50% 55%, transparent 55%, rgba(2, 8, 11, .55) 100%),
              linear-gradient(rgba(3, 10, 14, .5), transparent 16%, transparent 84%, rgba(3, 10, 14, .55));
}
.gem-targets { position: absolute; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.gem-target {
  position: absolute; left: 0; top: 0; padding: 0; border: 0; border-radius: 40%; background: transparent;
  pointer-events: auto; will-change: transform; transition: box-shadow .15s;
}
.gem-target:hover:enabled { background: transparent; transform: none; box-shadow: none; }
.gem-target:disabled { pointer-events: none; }
.gem-target:focus-visible { outline: 3px solid #ffe6a8; outline-offset: 2px; }

.arena-top {
  position: absolute; z-index: 3; top: 18px; left: 26px; right: 26px; pointer-events: none;
  display: flex; justify-content: center; align-items: center; gap: 16px;
}
.location { position: absolute; left: 0; font: 600 12px var(--sans); letter-spacing: 3px; color: #d9caa0; text-shadow: 0 2px 8px #000; }
.turn {
  display: inline-flex; align-items: center; gap: 10px; padding: 7px 18px 7px 14px; border-radius: 40px;
  font: 600 14px var(--sans); letter-spacing: 1.2px; text-transform: uppercase;
  background: var(--panel); border: 1px solid rgba(240, 194, 101, .45); color: #ffe9b8;
  backdrop-filter: blur(10px); box-shadow: 0 0 24px rgba(240, 168, 58, .22);
  transition: color .3s, border-color .3s, box-shadow .3s;
}
.turn::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; animation: beat 1.6s ease-in-out infinite; }
.turn[data-state=goblin] { color: #d5b8ff; border-color: rgba(181, 140, 255, .55); box-shadow: 0 0 24px rgba(160, 100, 255, .3); }
.turn[data-state=done] { color: #9ff0dc; border-color: rgba(79, 224, 196, .5); box-shadow: 0 0 24px rgba(79, 224, 196, .25); }
@keyframes beat { 0%, 100% { transform: scale(.75); opacity: .7; } 50% { transform: scale(1.1); opacity: 1; } }

/* ------------------------------------------------------------- panels */
.glass {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(14px) saturate(1.2); box-shadow: 0 18px 50px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.side-panel { position: absolute; z-index: 3; top: 72px; width: 268px; display: flex; flex-direction: column; gap: 14px; pointer-events: none; }
.side-panel > * { pointer-events: auto; }
.left-panel { left: 22px; }
.right-panel { right: 22px; align-items: stretch; }

.speech { padding: 14px 18px 16px; }
.speaker { display: flex; align-items: center; gap: 10px; }
.avatar { width: 40px; height: 40px; flex: none; filter: drop-shadow(0 0 8px rgba(143, 192, 78, .4)); }
.speaker span { font: 700 11px var(--sans); letter-spacing: 2px; color: var(--gold); }
.speech p { margin: 10px 0 0; font: italic 18px/1.5 var(--serif); color: #e7e6cf; }

.turn-info { padding: 14px 18px; border-left: 3px solid var(--gold); }
.turn-info #selection { margin: 6px 0 8px; font: 600 17px/1.4 var(--sans); color: var(--text); }
.move-help { font-size: 13px; color: var(--muted); }
.gem-count { display: flex; align-items: center; gap: 10px; padding: 0 6px; font-size: 15px; color: #a8ecd9; text-shadow: 0 2px 8px #000; }
.gem-count b { font: 700 24px var(--serif); color: #e9fff7; }
.gem-icon { width: 14px; height: 18px; background: linear-gradient(135deg, #7ff7d4, #2ee6b6 50%, #17a58a); clip-path: polygon(50% 0, 100% 30%, 82% 100%, 18% 100%, 0 30%); filter: drop-shadow(0 0 5px #2ee6b6); }

.lantern-station { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lantern-button {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 12px; border: 0; background: transparent !important;
  color: var(--gold); font-size: 14px; line-height: 1.35; text-align: center; width: 190px;
}
.lantern { width: 62px; height: 92px; transform-origin: 50% 4%; animation: sway 3.6s ease-in-out infinite; filter: drop-shadow(0 0 14px rgba(255, 196, 90, .55)); transition: filter .3s; }
.lantern-button:hover:enabled .lantern { filter: drop-shadow(0 0 28px rgba(255, 210, 110, .95)); }
.lantern-button:disabled .lantern { filter: grayscale(.8); animation: none; }
.flame { transform-origin: 40px 75px; animation: flicker 1.1s ease-in-out infinite; }
#hint-text {
  width: 100%; margin: 0; padding: 12px 14px; border-radius: 14px; font-size: 14px; line-height: 1.55; color: #f4e6bd;
  background: rgba(30, 24, 8, .72); border: 1px solid rgba(240, 194, 101, .5); backdrop-filter: blur(10px);
  box-shadow: 0 0 30px rgba(240, 168, 58, .18); animation: rise .4s ease;
}
#hint-text:empty { display: none; }
@keyframes sway { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes flicker { 0%, 100% { transform: scale(.92, 1); opacity: .82; } 50% { transform: scale(1.1, .88); opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.turn-actions { display: flex; flex-direction: column; gap: 10px; }
.turn-actions button, #restart { width: 100%; padding: 11px 14px; background: var(--panel); backdrop-filter: blur(10px); }
#restart { padding: 9px 14px; font-size: 14px; color: var(--muted); }
.primary {
  color: #2a1a04; font-weight: 700; letter-spacing: .3px; border-color: #ffdc8a;
  background: linear-gradient(180deg, #ffe08a, #e2a23a); box-shadow: 0 6px 24px rgba(240, 168, 58, .35), inset 0 1px 0 #fff8;
}
.turn-actions .primary { background: linear-gradient(180deg, #ffe08a, #e2a23a); font-size: 17px; padding: 14px; }
.primary:hover:enabled, .turn-actions .primary:hover:enabled { background: linear-gradient(180deg, #fff0b5, #f0b64a); border-color: #fff0b5; box-shadow: 0 8px 34px rgba(255, 190, 80, .6), inset 0 1px 0 #fff; }
.primary:disabled { box-shadow: none; background: rgba(240, 194, 101, .25) !important; color: #e8d7ab; border-color: rgba(240, 194, 101, .25); }
.primary:not(:disabled):not(.static) { animation: glow-pulse 2s ease-in-out infinite; }
@keyframes glow-pulse { 50% { box-shadow: 0 6px 38px rgba(255, 190, 80, .65), inset 0 1px 0 #fff8; } }

/* ------------------------------------------------------------ dialogs */
dialog {
  background: linear-gradient(180deg, #10272e, #0b1b21); color: var(--text); border: 1px solid rgba(240, 194, 101, .3);
  border-radius: 20px; padding: 34px; max-width: 700px; width: calc(100% - 30px); max-height: 86vh;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .65), 0 0 60px rgba(79, 224, 196, .08);
}
dialog[open] { animation: pop .3s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } }
dialog::backdrop { background: rgba(2, 8, 11, .78); backdrop-filter: blur(6px); }
dialog h2 { font: 400 28px/1.25 var(--serif); margin: 8px 0 16px; }
dialog h3 { font: 400 22px/1.3 var(--serif); color: #e9dfb4; }
dialog p { font-size: 16px; }
dialog a { color: var(--gold); }
.close { float: right; font-size: 24px; padding: 0 12px; line-height: 1.4; border-radius: 50%; }
.muted { font-size: 14px !important; }
.controls { width: min(480px, calc(100% - 30px)); }
.controls label { display: block; margin: 16px 0 8px; font-size: 15px; }
select, input:not([type=range]) {
  width: 100%; padding: 11px 12px; font-size: 15px; color: var(--text);
  background: #0a171c; border: 1px solid rgba(160, 220, 205, .25); border-radius: 10px;
}
.controls form button { margin-top: 12px; }
#custom-error { color: #ff9fb3; font-size: 14px; min-height: 1.4em; margin: 8px 0 0; }
.challenge-note { font-size: 15px; }
summary { cursor: pointer; color: var(--gold); }
details { margin: 16px 0; }
.math-table { overflow-x: auto; margin: 18px 0; }
.math-table table { width: 100%; border-collapse: collapse; font-size: 15px; }
.math-table caption { text-align: left; color: var(--gold); font-weight: 600; margin-bottom: 10px; }
.math-table th, .math-table td { text-align: center; padding: 10px 8px; border-bottom: 1px solid var(--line); color: var(--text); }
.math-table th:first-child { text-align: left; }
.math-table thead th { color: var(--gold); }
.math-table tbody tr:last-child { background: rgba(255, 255, 255, .03); }

#result { text-align: center; width: min(420px, calc(100% - 30px)); padding: 40px 34px; overflow: hidden; }
#result h2 { font-size: 38px; margin-bottom: 4px; }
#result p { margin: 14px 0 26px; }
.result-gem { font-size: 68px; line-height: 1; color: var(--gold); text-shadow: 0 0 40px rgba(255, 206, 100, .75); animation: gem-spin 4s ease-in-out infinite; }
#result[data-outcome=lose] .result-gem { color: var(--violet); text-shadow: 0 0 40px rgba(170, 110, 255, .8); }
@keyframes gem-spin { 0%, 100% { transform: rotateY(0) scale(1); } 50% { transform: rotateY(180deg) scale(1.12); } }

.fallback { padding: 100px 20px 20px; color: var(--gold); text-align: center; }
#fallback-gems { padding: 0 25px; max-height: 300px; overflow: auto; position: relative; z-index: 2; }
#fallback-gems button { margin: 3px; color: var(--gold); }
#fallback-gems [aria-pressed=true] { background: #82672e; }

/* ---------------------------------------------------- smaller screens */
@media (max-width: 1000px) {
  .side-panel { width: 230px; }
  .speech p { font-size: 16px; }
  .turn-info #selection { font-size: 15px; }
  .brand-text small { display: none; }
}
@media (max-width: 820px) {
  header { height: auto; min-height: 48px; padding: 6px 12px; gap: 6px; }
  .brand-text b { font-size: 11px; letter-spacing: 1.4px; }
  .sigil { width: 16px; height: 21px; }
  .header-actions { gap: 5px; }
  header button { font-size: 11px; padding: 5px 8px; }
  .arena { display: flex; flex-direction: column; height: auto; min-height: calc(100dvh - 90px); }
  #scene { position: relative; inset: auto; order: 2; flex: 1; min-height: 330px; }
  .vignette { display: none; }
  .arena-top { position: relative; order: 0; top: auto; left: auto; right: auto; padding: 6px 12px 0; justify-content: space-between; pointer-events: auto; }
  .location { position: static; font-size: 10px; letter-spacing: 2px; }
  .turn { font-size: 11px; padding: 4px 11px 4px 9px; }
  .side-panel { position: relative; top: auto; width: auto; pointer-events: auto; }
  .left-panel { order: 1; left: auto; padding: 6px 12px 0; gap: 6px; display: grid; grid-template-columns: 1fr auto; align-items: center; }
  .left-panel .speech { grid-column: 1 / -1; padding: 7px 12px; }
  .speech p { font-size: 13px; margin-top: 4px; line-height: 1.35; }
  .avatar { width: 26px; height: 26px; }
  .speaker span { font-size: 10px; }
  .turn-info { padding: 6px 12px; }
  .turn-info .eyebrow { display: none; }
  .turn-info #selection { font-size: 13px; margin: 0; }
  .move-help { display: none; }
  .gem-count { padding: 0; font-size: 12px; flex-direction: column; gap: 0; align-items: center; }
  .gem-icon { display: none; }
  .gem-count b { font-size: 20px; }
  .right-panel { order: 3; right: auto; padding: 6px 12px 12px; display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 8px; }
  .lantern-station { flex-direction: row; width: auto; }
  .lantern-button { width: auto; padding: 0 6px; }
  .lantern-button span { display: none; }
  .lantern { width: 32px; height: 48px; }
  #hint-text { position: fixed; left: 12px; right: 12px; bottom: 76px; width: auto; z-index: 20; }
  .turn-actions { flex: 1; flex-direction: row; min-width: 0; }
  .turn-actions button { padding: 10px 8px; font-size: 13px; width: auto; flex: 1; white-space: nowrap; }
  .turn-actions .primary { flex: 1.8; font-size: 14px; padding: 10px 6px; }
  #restart { width: auto; padding: 9px 10px; }
  dialog { padding: 24px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
