@font-face {
    font-family: "Ancient Tulip";
    src: url("../assets/Ancient-Tulip.ttf") format("truetype");
    font-display: block;
}

:root {
    --gold: #dcb766;
    --gold-dim: #a8884a;
    --ink: #0d0b09;
    --glass: rgba(14, 11, 8, 0.58);
    --line: rgba(220, 183, 102, 0.28);
    --text: #efe6d2;
    --muted: rgba(239, 230, 210, 0.62);
    --display: "Ancient Tulip", "Cinzel", Georgia, serif;
    --body: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--text); font-family: var(--body); }
body { -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- brand ---------- */
#sa { position: absolute; top: 18px; left: 22px; z-index: 5; opacity: 0.9; transition: opacity 0.2s; }
#sa:hover { opacity: 1; }
#sa img { display: block; height: 26px; width: auto; filter: drop-shadow(0 1px 8px rgba(0, 0, 0, 0.7)); }
#brand {
    position: absolute; top: 16px; left: 50%; transform: translateX(-50%); pointer-events: none !important; white-space: nowrap;
    font-family: var(--display); font-size: 26px; letter-spacing: 0.08em; color: var(--text);
    text-shadow: 0 1px 14px rgba(0, 0, 0, 0.8); opacity: 0.94; transition: opacity 0.6s;
}

/* ---------- top-right panel ---------- */
#panel {
    position: absolute; top: 16px; right: 16px; width: 262px; padding: 12px;
    background: var(--glass); border: 1px solid var(--line); border-radius: 14px;
    backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    transition: opacity 0.6s, transform 0.6s;
}
#share { position: relative; display: flex; height: 8px; margin: 8px 2px 2px; border-radius: 4px; background: rgba(255, 255, 255, 0.09); }
#share i { display: block; height: 100%; transition: width 0.5s; }
#share i:first-child { border-radius: 4px 0 0 4px; }
#share s { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; box-shadow: 0 0 4px rgba(0, 0, 0, 0.8); }
body:not(.state-game) #share { display: none; }
/* in a game the panel hangs under two small signs, and folds away behind the three lines */
#gamebar { position: absolute; top: 18px; right: 22px; z-index: 5; display: flex; gap: 14px; }
body:not(.state-game):not(.state-menu) #gamebar { display: none; }
body.state-menu #btn-leave { display: none; }
#gamebar button { width: 26px; height: 26px; padding: 0; border: 0; background: none; opacity: 0.9; transition: opacity 0.2s; }
#gamebar button:hover { opacity: 1; }
#gamebar svg { display: block; width: 26px; height: 26px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1px 8px rgba(0, 0, 0, 0.7)); }
body.state-game #panel, body.state-menu #panel { top: 56px; }
/* in the Exhibition the three lines fold away the panel and the card: the arrow keys and a click on a wonder still walk the table */
body.state-menu.menu-closed #card, body.state-menu.menu-closed #hint { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(16px); }
body.state-menu.menu-closed #hint { transform: none; }
body.menu-closed:is(.state-game, .state-menu) #panel { opacity: 0; pointer-events: none; transform: translateY(-8px); transition: opacity 0.25s, transform 0.25s; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); }
.seg button { border: 0; background: none; padding: 8px 6px; border-radius: 8px; font-size: 14px; letter-spacing: 0.04em; color: var(--muted); transition: background 0.2s, color 0.2s; }
.seg button:hover { color: var(--text); }
.seg button:disabled { opacity: 0.35; cursor: default; }
.seg button.on { background: linear-gradient(180deg, #e6c477, #b8934a); color: #1c1407; font-weight: 600; }
.seg.small { margin-top: 8px; }
.seg.small button { padding: 5px 6px; font-size: 12.5px; }

#seats { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
#seats li {
    display: grid; grid-template-columns: 22px 1fr auto auto; align-items: center; gap: 8px;
    padding: 6px 6px 6px 8px; border-radius: 9px; border: 1px solid transparent; transition: background 0.3s, border-color 0.3s;
}
#seats li.turn { background: rgba(220, 183, 102, 0.14); border-color: var(--line); }
#seats li.out { opacity: 0.45; }
.dot { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset -3px -4px 6px rgba(0, 0, 0, 0.45), inset 2px 2px 3px rgba(255, 255, 255, 0.35), 0 1px 3px rgba(0, 0, 0, 0.6); }
.seat-name { font-size: 15px; letter-spacing: 0.03em; }
.seat-score { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seat-score b { color: var(--gold); font-weight: 600; }
.seat-type {
    border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); border-radius: 7px; padding: 4px 8px; font-size: 12.5px; min-width: 86px; text-align: center;
}
.seat-type:hover { background: rgba(220, 183, 102, 0.18); }
.thinking::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

.tools { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.tools button { flex: 1 1 auto; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); border-radius: 7px; padding: 5px 8px; font-size: 12.5px; color: var(--muted); }
.tools button:hover { color: var(--text); background: rgba(220, 183, 102, 0.16); }
.tools button.off { text-decoration: line-through; opacity: 0.6; }
body:not(.state-game) .game-only { display: none; }
body:not(.state-menu) .menu-only { display: none; }
body:not(.state-game) .seat-score { display: none; }

/* ---------- wonder card ---------- */
#card {
    position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%); display: flex; align-items: center; gap: 18px;
    text-align: center; transition: opacity 0.5s, transform 0.5s;
}
.card-body { min-width: min(480px, 70vw); padding: 0 8px; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.85), 0 0 4px rgba(0, 0, 0, 0.6); }
#card-side { font-size: 12.5px; letter-spacing: 0.34em; text-transform: uppercase; color: var(--gold); }
#card-name { margin: 2px 0 0; font-family: var(--display); font-weight: 400; font-size: clamp(34px, 4.6vw, 58px); line-height: 1; letter-spacing: 0.04em; }
#card-place { margin-top: 6px; font-size: 15px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
#card-line { margin: 6px 0 12px; font-style: italic; font-size: 16px; }
#card-play {
    border: 1px solid var(--gold); border-radius: 999px; padding: 10px 34px; font-size: 15px; letter-spacing: 0.22em; text-transform: uppercase;
    background: linear-gradient(180deg, rgba(230, 196, 119, 0.95), rgba(176, 138, 66, 0.95)); color: #1c1407; font-weight: 600;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.5); transition: transform 0.15s, filter 0.2s;
}
#card-play:hover { transform: translateY(-1px); filter: brightness(1.1); }
#card-play.locked { background: rgba(14, 11, 8, 0.55); color: var(--muted); border-color: var(--line); cursor: default; font-weight: 400; }
.nav {
    width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); font-size: 30px; line-height: 1; padding-bottom: 5px;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: background 0.2s, transform 0.15s;
}
.nav:hover { background: rgba(220, 183, 102, 0.25); transform: scale(1.06); }
#hint { position: absolute; left: 0; right: 0; bottom: 16px; text-align: center; font-size: 12.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); text-shadow: 0 1px 8px #000; transition: opacity 0.5s; }

/* ---------- in game ---------- */
#status {
    position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); padding: 8px 22px; border-radius: 999px;
    background: var(--glass); border: 1px solid var(--line); font-size: 15px; letter-spacing: 0.12em; text-transform: uppercase;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: opacity 0.4s; white-space: nowrap;
}
#status:empty { opacity: 0; }
#actions { position: absolute; left: 50%; bottom: 78px; transform: translateX(-50%); display: flex; gap: 10px; }
#actions button {
    border: 1px solid var(--gold); border-radius: 999px; padding: 9px 26px; white-space: nowrap;
    font-size: 14px; letter-spacing: 0.2em; text-transform: uppercase; font-weight: 600; color: #1c1407;
    background: linear-gradient(180deg, rgba(230, 196, 119, 0.95), rgba(176, 138, 66, 0.95)); box-shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
}
#actions button:hover { filter: brightness(1.1); }
body:not(.state-game) #actions { display: none; }
#toast {
    position: absolute; left: 50%; top: 22%; transform: translate(-50%, 0); font-family: var(--display); font-size: clamp(34px, 6vw, 68px); letter-spacing: 0.08em;
    color: #fff3d6; text-shadow: 0 0 30px rgba(255, 190, 90, 0.75), 0 3px 20px rgba(0, 0, 0, 0.8); opacity: 0; pointer-events: none !important; white-space: nowrap;
}
#toast.small { font-family: var(--body); font-size: 19px; letter-spacing: 0.1em; text-transform: uppercase; }
#toast.osiris { color: #d6ffe0; text-shadow: 0 0 34px rgba(90, 255, 150, 0.8), 0 3px 20px rgba(0, 0, 0, 0.8); }
#toast.show { animation: toast 2.2s ease-out forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 14px) scale(0.94); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -10px) scale(1.02); } }

/* ---------- state switching ---------- */
body:not(.state-menu) #card, body:not(.state-menu) #hint { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(16px); }
body:not(.state-menu) #hint { transform: none; }
body:not(.state-game) #status, body:not(.state-game) #toast { display: none; }
body.state-intro #panel, body.state-intro #brand, body.state-travel #panel { opacity: 0; pointer-events: none; }
body.state-travel #panel { transform: translateY(-8px); }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(8, 6, 4, 0.5), rgba(8, 6, 4, 0.86)); animation: fade 0.35s ease-out; padding: 20px; }
@keyframes fade { from { opacity: 0; } }
#rules, #keywords { animation-duration: 0.16s; }
.papyrus {
    position: relative; width: min(680px, 100%); max-height: min(86vh, 860px); overflow-y: auto; padding: 34px 44px 38px; color: #2c1c0c; border-radius: 4px;
    background:
        repeating-linear-gradient(0deg, rgba(120, 84, 40, 0.07) 0 2px, transparent 2px 5px),
        repeating-linear-gradient(90deg, rgba(120, 84, 40, 0.06) 0 3px, transparent 3px 7px),
        radial-gradient(ellipse at center, #e9d3a0 30%, #cfae72 100%);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), inset 0 0 60px rgba(110, 70, 20, 0.35);
    animation: unroll 0.16s ease-out;
    user-select: text; -webkit-user-select: text;
    /* the computer's own scrollbar is hidden; a thin ink line drawn on the paper shows where you are */
    scrollbar-width: none;
}
.papyrus::-webkit-scrollbar { display: none; }
.papyrus .bar { position: absolute; right: 5px; top: 0; width: 4px; border-radius: 2px; background: rgba(90, 44, 16, 0.38); pointer-events: none; transition: opacity 0.3s; }
@keyframes unroll { from { opacity: 0; transform: translateY(-6px); } }
.papyrus .sigil { display: block; width: 54px; margin: 0 auto 4px; opacity: 0.8; }
.papyrus h2 { margin: 0 0 12px; text-align: center; font-family: var(--display); font-weight: 400; font-size: 46px; letter-spacing: 0.06em; }
.papyrus h3 { margin: 18px 0 4px; font-family: var(--display); font-weight: 400; font-size: 23px; letter-spacing: 0.08em; text-align: center; color: #5a2c10; }
.papyrus p { margin: 7px 0; font-size: 17px; line-height: 1.5; min-height: 1.5em; }
.papyrus p b { color: #7a2a10; letter-spacing: 0.08em; }
.papyrus .close { position: absolute; top: 10px; right: 14px; border: 0; background: none; font-size: 30px; color: #5a3a1a; }
.papyrus .more { display: block; margin: 22px auto 0; border: 1px solid rgba(90, 44, 16, 0.4); border-radius: 999px; background: rgba(255, 245, 220, 0.25); padding: 7px 20px; font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase; color: #5a2c10; }
.papyrus .more:hover { background: rgba(255, 245, 220, 0.5); }
.papyrus .note { text-align: center; font-style: italic; font-size: 15.5px; color: #5a3a1a; margin: -4px 0 6px; }
.papyrus .note b { font-style: normal; color: #7a2a10; letter-spacing: 0.06em; }
#keywords .papyrus { width: min(760px, 100%); }
#keywords-list .kw { display: grid; grid-template-columns: 9.5em 1fr; column-gap: 16px; padding: 8px 10px; border-bottom: 1px solid rgba(90, 44, 16, 0.15); border-radius: 3px; opacity: 0.62; }
#keywords-list .kw.mine { opacity: 1; background: rgba(255, 240, 200, 0.42); box-shadow: inset 3px 0 0 #7a2a10; }
#keywords-list .kw b { grid-row: span 2; color: #7a2a10; letter-spacing: 0.08em; text-transform: uppercase; font-size: 14.5px; padding-top: 2px; }
#keywords-list .kw p { margin: 0; min-height: 0; font-size: 16px; line-height: 1.42; }
#keywords-list .kw small { margin-top: 3px; font-size: 12.5px; letter-spacing: 0.08em; text-transform: uppercase; color: #6b4a26; }
#keywords-list .kw small strong { color: #7a2a10; }
@media (max-width: 720px) { #keywords-list .kw { grid-template-columns: 1fr; } #keywords-list .kw b { grid-row: auto; } }

.banner { text-align: center; padding: 34px 54px; border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold); background: linear-gradient(90deg, transparent, rgba(14, 11, 8, 0.82) 20%, rgba(14, 11, 8, 0.82) 80%, transparent); width: 100%; }
.banner h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(34px, 6vw, 70px); letter-spacing: 0.05em; color: #fff0cc; text-shadow: 0 0 40px rgba(255, 190, 90, 0.5); }
.banner p { margin: 10px 0 22px; font-size: 18px; font-style: italic; color: var(--muted); }
.banner .row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.banner button, #intro button {
    border: 1px solid var(--gold); border-radius: 999px; padding: 10px 28px; font-size: 14px; letter-spacing: 0.2em; text-transform: uppercase; background: rgba(220, 183, 102, 0.12);
    transition: background 0.2s;
}
.banner button:hover, #intro button:not(:disabled):hover { background: rgba(220, 183, 102, 0.35); }
.banner a { display: inline-block; text-decoration: none; padding: 11px 22px; border: 1px solid var(--gold); border-radius: 999px; background: rgba(220, 183, 102, 0.2); color: #fff0cc; font-size: 16px; letter-spacing: 0.06em; }
.banner a:hover { background: rgba(220, 183, 102, 0.4); }
#arcade .banner p { max-width: 30em; margin-left: auto; margin-right: auto; }
#arcade .banner button { padding: 11px 22px; font-size: 16px; letter-spacing: 0.06em; text-transform: none; color: #fff0cc; }
#brand small { display: none; margin-left: 0.7em; font-family: Georgia, serif; font-size: 0.42em; letter-spacing: 0.22em; text-transform: uppercase; vertical-align: middle; padding: 2px 8px; border: 1px solid var(--gold); border-radius: 999px; color: var(--gold); }
body.demo #brand small { display: inline-block; }
.seg button.arcade { opacity: 0.55; }
.seg button.arcade::after { content: ' ·  Arcade'; font-size: 0.78em; letter-spacing: 0.08em; }
#gameover { background: radial-gradient(ellipse at center, rgba(8, 6, 4, 0.2), rgba(8, 6, 4, 0.7)); }

/* ---------- intro ---------- */
#intro {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
    background: radial-gradient(ellipse at 50% 40%, rgba(13, 11, 9, 0.55), rgba(13, 11, 9, 0.96) 75%); transition: opacity 1.4s ease, visibility 1.4s;
}
#intro h1 { margin: 6px 0 30px; font-family: var(--display); font-weight: 400; font-size: clamp(46px, 9vw, 110px); letter-spacing: 0.05em; line-height: 1; text-shadow: 0 4px 40px rgba(0, 0, 0, 0.8); }
#intro p { margin: 6px 0 26px; letter-spacing: 0.4em; text-transform: uppercase; font-size: 13.5px; color: var(--gold); }
#intro button:disabled { opacity: 0.55; cursor: default; border-color: var(--line); }
#intro small { position: absolute; bottom: 18px; color: var(--muted); letter-spacing: 0.1em; font-size: 11.5px; }
body:not(.state-intro) #intro { opacity: 0; visibility: hidden; pointer-events: none; }

@media (max-width: 720px) {
    #brand { display: none; }
    #panel { width: 214px; padding: 8px; top: 10px; right: 10px; }
    body.state-game #panel, body.state-menu #panel { top: 48px; }
    #gamebar { top: 12px; right: 14px; }
    .seat-type { min-width: 70px; padding: 4px 5px; }
    #card { bottom: 38px; gap: 6px; }
    #card-line { font-size: 15px; }
    .nav { width: 42px; height: 42px; font-size: 24px; }
    .papyrus { padding: 26px 22px; }
    #hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01s !important; } }
