/* Fonts bundled locally (SIL Open Font License): Cinzel, EB Garamond */
@font-face { font-family: 'Cinzel'; font-style: normal; font-weight: 400 900; font-display: swap; src: url('fonts/Cinzel.woff2') format('woff2'); }
@font-face { font-family: 'EB Garamond'; font-style: normal; font-weight: 400 800; font-display: swap; src: url('fonts/EBGaramond.woff2') format('woff2'); }
@font-face { font-family: 'EB Garamond'; font-style: italic; font-weight: 400; font-display: swap; src: url('fonts/EBGaramond-Italic.woff2') format('woff2'); }

:root {
  --bg: #120e1f;
  --bg2: #1c1630;
  --panel: rgba(36, 28, 60, 0.82);
  --line: rgba(214, 186, 120, 0.25);
  --gold: #d8b46a;
  --gold-hi: #f3d892;
  --text: #ece4d4;
  --muted: #a99fbe;
  --violet: #8b6cf0;
  --light-sq: #e9dcbf;
  --dark-sq: #8a6a4c;
  --danger: #e2685a;
  --ok: #7fcf8f;
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at top, #2a1f4a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
}
.stars {
  position: fixed; inset: 0; pointer-events: none; opacity: .5;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #fff8, transparent),
    radial-gradient(1px 1px at 70% 20%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 40% 80%, #fff5, transparent),
    radial-gradient(1px 1px at 85% 65%, #fff7, transparent),
    radial-gradient(1px 1px at 10% 70%, #fff5, transparent),
    radial-gradient(1.5px 1.5px at 55% 45%, #fff4, transparent);
}
.hidden { display: none !important; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .04em; margin: 0; }
h2 { color: var(--gold-hi); font-size: 1.4rem; }
h3 { color: var(--gold); font-size: 1.05rem; margin-bottom: .6rem; }

/* ---------- buttons & inputs */
.btn {
  font-family: var(--display); font-size: 1rem; letter-spacing: .05em;
  color: var(--text); background: linear-gradient(#2e2550, #231c3e);
  border: 1px solid var(--line); border-radius: 10px;
  padding: .75rem 1.4rem; cursor: pointer; transition: transform .1s, border-color .2s, box-shadow .2s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); box-shadow: 0 0 18px #d8b46a33; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: linear-gradient(#e2c27a, #b88f45); color: #21182f; border-color: #f3d892; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.small { font-size: .85rem; padding: .45rem .9rem; }
.btn small { display: block; font-family: var(--serif); font-size: .8rem; color: var(--muted); letter-spacing: 0; }
.btn.primary small { color: #3b2c1a; }
.link { background: none; border: 0; color: var(--gold); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
.input, select {
  font: inherit; color: var(--text); background: #120e22; border: 1px solid var(--line);
  border-radius: 8px; padding: .55rem .75rem; width: 100%;
}
.input:focus, select:focus { outline: 2px solid var(--violet); outline-offset: 1px; }
.input.code { text-transform: uppercase; letter-spacing: .3em; font-family: var(--display); text-align: center; margin-bottom: .8rem; }
.field { display: block; color: var(--muted); font-size: .9rem; margin-bottom: .8rem; }
.field select { margin-top: .3rem; }

/* ---------- screens */
.screen { display: none; position: relative; min-height: 100vh; padding: 24px 16px 48px; }
.screen.active { display: block; animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 900px; margin: 0 auto 24px; }

.title-wrap { min-height: 90vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.eyebrow { color: var(--muted); font-style: italic; margin: 0 0 .5rem; }
.logo { font-size: clamp(2.6rem, 9vw, 5rem); color: var(--text); line-height: 1.05; text-shadow: 0 0 30px #8b6cf055; }
.logo span { color: var(--gold-hi); }
.tagline { color: var(--muted); margin: .6rem 0 2rem; font-size: 1.2rem; }
.menu { display: grid; gap: 12px; width: min(320px, 100%); }

/* ---------- story map */
.chapters { list-style: none; padding: 0; margin: 0 auto; max-width: 900px; display: grid; gap: 12px; }
.chapter { display: flex; gap: 16px; align-items: flex-start; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.chapter.open, .chapter.done { cursor: pointer; transition: border-color .2s, transform .15s; }
.chapter.open:hover, .chapter.done:hover, .chapter:focus { border-color: var(--gold); transform: translateX(3px); outline: none; }
.chapter.locked { opacity: .5; }
.chapter.open { border-color: var(--gold); box-shadow: 0 0 24px #d8b46a22; }
.ch-num { flex: 0 0 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-size: 1.2rem; background: #120e22; border: 1px solid var(--line); color: var(--gold); }
.chapter.done .ch-num { background: var(--gold); color: #21182f; }
.ch-body h3 { margin: 0; }
.ch-opp { margin: .1rem 0; color: var(--text); font-style: italic; }
.ch-twist { margin: 0; color: var(--muted); font-size: .95rem; }
.footnote { text-align: center; color: var(--muted); font-size: .9rem; margin-top: 24px; }

/* ---------- lobby */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel.narrow { max-width: 460px; margin: 0 auto; }
.lobby { display: grid; gap: 14px; max-width: 900px; margin: 0 auto; grid-template-columns: 1fr; }
@media (min-width: 760px) { .lobby { grid-template-columns: 1fr 1fr; } .lobby .panel:first-child { grid-column: 1 / -1; } }
.twist { color: var(--muted); font-size: .95rem; font-style: italic; min-height: 2.6em; }
.waiting { max-width: 600px; margin: 16px auto 0; text-align: center; }
.share { display: flex; gap: 8px; }
.code-big { font-family: var(--display); font-size: 2rem; letter-spacing: .3em; color: var(--gold-hi); margin: .6rem 0; }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--danger); text-align: center; min-height: 1.5em; }

/* ---------- game layout */
.game { display: flex; gap: 24px; max-width: 1200px; margin: 0 auto; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.board-col { flex: 0 1 min(88vh - 110px, 640px); min-width: 280px; width: 100%; }
.side { flex: 1 1 300px; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.sub { margin: -6px 0 0; color: var(--muted); font-style: italic; }
.twist-box { background: #120e22aa; border-left: 3px solid var(--violet); padding: 8px 12px; border-radius: 6px; }
.twist-box strong { font-family: var(--display); font-size: .8rem; color: var(--violet); letter-spacing: .1em; text-transform: uppercase; }
.twist-box p { margin: 2px 0 0; font-size: .95rem; }
.status { font-family: var(--display); font-size: 1rem; color: var(--gold-hi); min-height: 1.5em; }
.status.over { color: var(--text); }
.move-list { list-style: decimal; margin: 0; padding: 4px 4px 4px 2.2em; max-height: 220px; overflow-y: auto; font-size: .9rem; background: #120e2280; border-radius: 8px; }
.move-list:empty { display: none; }
.move-list li { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; color: var(--muted); }
.move-list li::marker { color: var(--gold); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.player-bar { display: flex; align-items: center; gap: 10px; padding: 6px 4px; font-family: var(--display); font-size: .95rem; }
.player-bar .dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid #000a; }
.player-bar .dot.w { background: #fdf6e3; }
.player-bar .dot.b { background: #1b1430; border-color: var(--gold); }
.pname { color: var(--muted); }
.pname.active { color: var(--gold-hi); text-shadow: 0 0 12px #d8b46a66; }
.pname em { font-family: var(--serif); color: var(--muted); }
.pcolor { margin-left: auto; color: var(--muted); font-size: .8rem; }

/* ---------- board */
.board {
  --w: 8; --h: 8;
  display: grid; grid-template-columns: repeat(var(--w), 1fr); grid-template-rows: repeat(var(--h), 1fr);
  aspect-ratio: var(--w) / var(--h); width: 100%;
  border: 6px solid #3a2a1c; border-radius: 6px; box-shadow: 0 0 0 1px var(--gold), 0 20px 50px #0009, 0 0 60px #8b6cf022;
  user-select: none; position: relative; transition: filter .3s;
}
.board.veiled { filter: blur(14px) brightness(.3); pointer-events: none; }
.sq { position: relative; display: grid; place-items: center; container-type: size; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.movable { cursor: pointer; }
.sq.last::after { content: ''; position: absolute; inset: 0; background: #f5d35a55; pointer-events: none; }
.sq.selected::after { content: ''; position: absolute; inset: 0; background: #8b6cf088; box-shadow: inset 0 0 0 3px #b8a2ff; pointer-events: none; }
.sq.target { cursor: pointer; }
.sq.target::before { content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: #5b3fc8aa; z-index: 2; pointer-events: none; }
.sq.target-capture { cursor: pointer; }
.sq.target-capture::before { content: ''; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid #5b3fc8bb; z-index: 2; pointer-events: none; }
.sq.check { background: radial-gradient(circle, #ff4b3e 0%, #c0302599 45%, transparent 75%), var(--dark-sq); }
.sq.chasm { background: radial-gradient(circle at 50% 40%, #2a2340 0%, #07050d 75%) !important; box-shadow: inset 0 0 12px #000; }
.sq.chasm::before { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(115deg, transparent 0 9px, #ffffff08 9px 10px); }
.sq.portal { overflow: hidden; }
.sq.portal::before { content: ''; position: absolute; inset: 8%; border-radius: 50%; border: 3px solid var(--pc); box-shadow: 0 0 14px var(--pc), inset 0 0 14px var(--pc); animation: spin 6s linear infinite; z-index: 0; }
.portal-0 { --pc: #39d6ff; }
.portal-1 { --pc: #ff5fd2; }
@keyframes spin { to { transform: rotate(360deg); } }
.sq.fog { background: linear-gradient(135deg, #3c3a52, #24223a) !important; }
.sq.fog::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 30% 40%, #ffffff14, transparent 60%), radial-gradient(circle at 70% 70%, #ffffff10, transparent 55%); pointer-events: none; }
.sq.boom { animation: boom .9s ease-out; }
@keyframes boom { 0% { box-shadow: inset 0 0 0 100px #ff9a2e; } 100% { box-shadow: inset 0 0 0 0 #ff9a2e00; } }
.coord { position: absolute; font-family: var(--display); font-size: clamp(8px, 14cqh, 13px); font-weight: 700; pointer-events: none; opacity: .75; z-index: 3; }
.coord.rank { top: 3%; left: 5%; }
.coord.file { bottom: 2%; right: 6%; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord, .sq.chasm .coord, .sq.fog .coord { color: var(--light-sq); }

.piece { position: relative; z-index: 1; font-size: 78cqh; line-height: 1; display: grid; place-items: center; width: 100%; height: 100%; pointer-events: none; font-family: 'Apple Symbols', 'Segoe UI Symbol', 'DejaVu Sans', 'Noto Sans Symbols2', sans-serif; }
.piece.white { color: #fffaf0; -webkit-text-stroke: 1.5px #2a1f14; text-shadow: 0 2px 3px #0007; }
.piece.black { color: #1d1530; -webkit-text-stroke: 1px #d8b46a; text-shadow: 0 2px 3px #0006; }
.piece.fantasy svg { width: 80%; height: 80%; filter: drop-shadow(0 2px 2px #0008); }
.piece.white.fantasy svg { fill: #fffaf0; stroke: #2a1f14; stroke-width: 4; }
.piece.black.fantasy svg { fill: #1d1530; stroke: #d8b46a; stroke-width: 3.5; }
.piece.fantasy .cut { fill: #8b6cf0; stroke: none; }
.piece.black.fantasy .cut { fill: #e2a64a; }

/* ---------- online box */
.online-box { display: flex; flex-direction: column; gap: 8px; }
.room-line { font-family: var(--display); font-size: .9rem; color: var(--muted); }
.room-line b { color: var(--gold-hi); letter-spacing: .2em; }
.opp-status { font-size: .9rem; color: var(--muted); }
.opp-status.ok { color: var(--ok); }
.opp-status.warn { color: var(--danger); }
.chat-log { max-height: 140px; overflow-y: auto; font-size: .9rem; background: #120e2280; border-radius: 8px; padding: 4px 8px; }
.chat-log:empty { display: none; }
.chat { margin: 2px 0; }
.chat.system { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 6px; }

/* ---------- dialogue */
.dialogue { position: fixed; inset: 0; z-index: 40; background: linear-gradient(transparent 30%, #000c); display: flex; align-items: flex-end; justify-content: center; padding: 16px; animation: fade .3s; cursor: pointer; }
.dialogue-box { width: min(760px, 100%); background: linear-gradient(#2a2147f2, #1a1430f7); border: 1px solid var(--gold); border-radius: 16px; padding: 18px 22px; box-shadow: 0 0 40px #8b6cf044; cursor: default; margin-bottom: 4vh; }
.speaker { font-family: var(--display); color: var(--gold-hi); font-size: 1.1rem; letter-spacing: .06em; }
.dialogue[data-who="narrator"] .speaker { color: var(--muted); font-style: italic; }
.dialogue[data-who="narrator"] #dlg-text { font-style: italic; }
#dlg-text { font-size: 1.2rem; margin: .4rem 0 .8rem; min-height: 3em; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- modal */
.modal { position: fixed; inset: 0; z-index: 50; background: #07050dcc; display: grid; place-items: center; padding: 16px; animation: fade .25s; }
.modal-box { width: min(560px, 100%); max-height: 88vh; overflow-y: auto; background: var(--bg2); border: 1px solid var(--gold); border-radius: 16px; padding: 22px; box-shadow: 0 0 60px #8b6cf033; }
.modal-box h2 { margin-bottom: .4rem; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.bestiary { display: grid; gap: 10px; }
.beast { display: flex; gap: 14px; align-items: center; }
.beast p { margin: 0; color: var(--muted); font-size: .95rem; }
.beast-pieces { flex: 0 0 96px; display: flex; gap: 4px; }
.beast-pieces .piece { width: 46px; height: 46px; font-size: 38px; background: var(--light-sq); border-radius: 6px; }
.beast-pieces .piece:nth-child(2) { background: var(--dark-sq); }
.mini { width: 46px; height: 46px; border-radius: 6px; position: relative; display: inline-block; }
.mini.chasm { background: radial-gradient(circle at 50% 40%, #2a2340, #07050d 75%); }
.mini.portal { background: var(--dark-sq); }
.mini.portal::before { content: ''; position: absolute; inset: 8%; border-radius: 50%; border: 3px solid var(--pc); box-shadow: 0 0 10px var(--pc); }
.mini.fog { background: linear-gradient(135deg, #3c3a52, #24223a); }

@media (max-width: 760px) {
  body { font-size: 16px; }
  .screen { padding: 16px 16px 40px; }
  .side { max-width: none; }
  .game { gap: 14px; }
}

/* ---------- platform / CrazyGames */
.cg-only { display: none; }
.on-crazygames .cg-only { display: block; }
.on-crazygames .cg-hide { display: none !important; }
.note { color: var(--gold-hi); text-align: center; min-height: 1.5em; margin: 12px auto 0; max-width: 600px; }
.privacy { color: var(--muted); font-size: .8rem; text-align: center; max-width: 600px; margin: 8px auto 0; }
.quick-chat { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-chat button { font: inherit; font-size: .85rem; color: var(--text); background: #120e22; border: 1px solid var(--line); border-radius: 999px; padding: .2rem .7rem; cursor: pointer; }
.quick-chat button:hover { border-color: var(--gold); }

/* Touch devices: no accidental text selection, callouts or double-tap zoom */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
input, textarea { -webkit-user-select: text; user-select: text; }
.board, .btn, .sq { touch-action: manipulation; }

/* Short, wide screens such as the CrazyGames player (907×510): keep everything in view */
@media (max-height: 640px) and (min-width: 700px) {
  body { font-size: 15px; }
  .screen { padding: 10px 14px; min-height: 100vh; }
  .title-wrap { min-height: calc(100vh - 20px); }
  .logo { font-size: clamp(2rem, 11vh, 4rem); }
  .tagline { margin: .2rem 0 .8rem; }
  .menu { gap: 6px; }
  .btn { padding: .45rem 1rem; }
  .game { gap: 14px; flex-wrap: nowrap; align-items: stretch; }
  .board-col { flex: 0 0 auto; width: calc(100vh - 80px); min-width: 0; }
  .player-bar { padding: 2px 4px; font-size: .8rem; }
  .side { max-height: calc(100vh - 20px); overflow-y: auto; padding: 12px; gap: 8px; flex: 1 1 260px; }
  .side h2 { font-size: 1.1rem; }
  .twist-box p { font-size: .85rem; }
  .move-list { max-height: 90px; }
  .chat-log { max-height: 70px; }
  .screen-head { margin-bottom: 10px; }
  .chapter { padding: 8px 12px; }
  .ch-num { flex-basis: 34px; height: 34px; font-size: 1rem; }
  #dlg-text { font-size: 1.05rem; min-height: 2em; }
  .dialogue-box { margin-bottom: 1vh; padding: 12px 16px; }
}

/* Portals without invite-link support: players share the 5-letter code instead */
.no-invite-links #btn-copy2, .no-invite-links .share { display: none !important; }
.no-invite-links .room-line::after { content: ' — tell your friend this code'; color: var(--muted); font-family: var(--serif); }
/* While a portal ad is showing, ignore clicks on the game */
.ad-playing .screen { pointer-events: none; }

/* Builds without online duels (portals that forbid outside servers) */
.no-online [data-go="duel"] { display: none !important; }

/* Portal "disable chat" setting: hide all player chat */
.chat-off .quick-chat, .chat-off .chat-form, .chat-off .chat-log .chat:not(.system) { display: none !important; }
