/* Ra — modern interface */
:root {
  --bg: #f3e9d2; --panel: #fffaf0; --panel-2: #fbf2df; --ink: #1f2430; --muted: #6e6455; --line: #e3d3b2;
  --lapis: #1d3557; --lapis-2: #2f5d9a; --gold: #c9971c; --gold-2: #f3cf5a; --red: #b23a48; --green: #2e7d4f;
  --you: #2f5d9a; --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 4px 14px rgba(60, 40, 10, .08);
  --dock-h: 0px; --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #10151e; --panel: #19212e; --panel-2: #1f2938; --ink: #ece5d6; --muted: #a59b88; --line: #2d3848;
    --lapis: #9dbce8; --lapis-2: #6f9fe0; --gold: #e2b23a; --gold-2: #f5d76e; --red: #e36b78; --green: #5cc08a; --you: #7fb0f0;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.35); color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; padding-bottom: calc(var(--dock-h) + 8px); }
button { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- header ---- */
#top { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--lapis); color: #f8f1df; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { #top { background: #0b1f3a; } }
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { font: 700 22px/1 Georgia, "Times New Roman", serif; letter-spacing: .12em; }
.logo { color: var(--gold-2); font-size: 22px; }
.track { display: flex; gap: 5px; align-items: center; }
.track .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.55); }
.track .dot.on { background: radial-gradient(circle at 35% 35%, #ffe08a, #e0532b); border-color: #ffd36b; }
.track .lbl { font-size: 13px; opacity: .85; margin-left: 4px; white-space: nowrap; }
.hdr-info { display: flex; gap: 6px; }
.chip { background: rgba(255,255,255,.14); border-radius: 999px; padding: 2px 10px; font-size: 13px; white-space: nowrap; }
.hdr-actions { margin-left: auto; display: flex; gap: 4px; }
.ghost { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #f8f1df; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.ghost:hover { background: rgba(255,255,255,.12); }
.ghost.icon { font-size: 17px; padding: 2px 9px; }
#btnMore { display: none; }
.scores h3 { margin: 14px 0 4px; font-size: 15px; } .scores h3:first-child { margin-top: 0; }
.scores .note { margin: 2px 0 6px; font-size: 12.5px; color: var(--muted); }
.table-wrap { overflow-x: auto; }

/* ---- prompt banner ---- */
#banner { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.banner-text { flex: 1 1 280px; min-width: 0; }
#prompt { font-weight: 650; font-size: 16px; }
#subprompt { color: var(--muted); font-size: 13.5px; }
#banner.yours { border-left: 5px solid var(--you); }
#banner.bidding { border-left: 5px solid var(--red); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; min-height: 40px; }
.btn:hover:not(:disabled) { border-color: var(--lapis-2); }
.btn.primary { background: var(--lapis-2); border-color: var(--lapis-2); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sunbtn { display: inline-flex; align-items: center; gap: 6px; }
#hintBox { flex: 1 1 100%; margin: 0; max-height: 40vh; overflow: auto; padding: 10px 14px; background: color-mix(in srgb, var(--gold-2) 22%, var(--panel)); border: 1px solid var(--gold); border-radius: 10px; white-space: pre-wrap; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
#hintBox button { margin-left: auto; background: none; border: 0; cursor: pointer; font-size: 16px; color: var(--muted); }

/* ---- table layout ---- */
#table { display: grid; grid-template-columns: minmax(250px, 300px) 1fr minmax(210px, 260px); gap: 14px; padding: 14px 16px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.panel-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.panel-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#blockPanel { position: sticky; top: calc(var(--banner-h, 66px) + 10px); }
.block-row { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.sun-on-block { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }
.slots { display: grid; grid-template-columns: repeat(4, 60px); gap: 7px; }
.slot { width: 60px; height: 60px; border-radius: 9px; border: 2px dashed var(--line); display: flex; align-items: center; justify-content: center; position: relative; padding: 0; background: transparent; }
.slot img { width: 100%; height: 100%; border-radius: 7px; display: block; }
.slot.filled { border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.slot.ra img { outline: 3px solid #e0532b; }
.slot.pick { cursor: pointer; outline: 3px solid var(--gold); outline-offset: 2px; animation: pulse 1.2s ease-in-out infinite; }
.slot.pick.nope { outline-color: transparent; animation: none; opacity: .5; cursor: not-allowed; }
@keyframes pulse { 50% { outline-color: color-mix(in srgb, var(--gold) 35%, transparent); } }
.slot .cap { position: absolute; bottom: -1px; left: 0; right: 0; font-size: 9.5px; text-align: center; background: rgba(0,0,0,.55); color: #fff; border-radius: 0 0 7px 7px; line-height: 13px; }

/* ---- players ---- */
#players { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px; position: relative; min-height: 112px; transition: box-shadow .2s, border-color .2s; }
.pcard.turn { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 45%, transparent), var(--shadow); }
.pcard.out { opacity: .72; }
.phead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.pname { font-weight: 700; font-size: 16px; }
.pscore { margin-left: auto; font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.pscore small { font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 3px; }
.badge { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.most { background: color-mix(in srgb, var(--gold-2) 40%, var(--panel)); border-color: var(--gold); }
.badge.fewest { background: color-mix(in srgb, var(--red) 15%, var(--panel)); border-color: color-mix(in srgb, var(--red) 50%, var(--line)); }
.sunrow { display: flex; gap: 6px; margin-bottom: 7px; align-items: center; }
.sun { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; color: #5a3a00;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #f2c53d 55%, #d79a12); border: 2px solid #c77d0a; flex: none; font-variant-numeric: tabular-nums; }
.sun.big { width: 58px; height: 58px; font-size: 24px; }
.sun.down { background: repeating-linear-gradient(45deg, #8a7a5a, #8a7a5a 4px, #7a6a4a 4px, #7a6a4a 8px); border-color: #5e5038; color: #f2e6c8; }
.sun.down.secret { color: transparent; }
.sun.bid { box-shadow: 0 0 0 3px var(--red); }
.sun.paid { box-shadow: 0 0 0 3px var(--green); }
.tiles { display: flex; flex-wrap: wrap; gap: 5px; }
.tg { position: relative; width: 36px; height: 36px; }
.tg img { width: 36px; height: 36px; border-radius: 6px; display: block; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.tg .n { position: absolute; right: -4px; bottom: -4px; background: var(--ink); color: var(--panel); font-size: 11px; font-weight: 800; border-radius: 999px; min-width: 17px; height: 17px; line-height: 17px; text-align: center; padding: 0 3px; }
.tg.lost img { opacity: .35; filter: grayscale(1); }
.tg.pick { cursor: pointer; } .tg.pick img { outline: 3px solid var(--gold); outline-offset: 1px; }
.tg.chosen img { outline: 3px solid var(--red); opacity: .5; }
.empty { font-size: 12.5px; color: var(--muted); font-style: italic; }
.bubble { position: absolute; top: -10px; right: 12px; background: var(--ink); color: var(--panel); font-size: 12.5px; font-weight: 700; padding: 2px 10px; border-radius: 999px; box-shadow: var(--shadow); }
.bubble.pass { background: var(--muted); }
.bubble.win { background: var(--green); }

/* ---- you (dock) ---- */
#dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--panel); border-top: 2px solid var(--you); box-shadow: 0 -4px 18px rgba(0,0,0,.12); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
#dock:empty { display: none; }
.you { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; max-width: 1400px; margin: 0 auto; }
.you .who { display: flex; flex-direction: column; min-width: 90px; }
.you .who .pname { color: var(--you); }
.you .proj { font-size: 12.5px; color: var(--muted); background: none; border: 0; padding: 0; text-align: left; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.breakdown { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.breakdown .pos { color: var(--green); } .breakdown .neg { color: var(--red); }
.you .sunrow { margin: 0; }
.you .sun { width: 42px; height: 42px; font-size: 17px; }
.you .sun.can { cursor: pointer; box-shadow: 0 0 0 3px var(--lapis-2); }
.you .tiles { flex: 1; }
.you.turn { }

/* ---- feed ---- */
#feedPanel { position: sticky; top: calc(var(--banner-h, 66px) + 10px); max-height: calc(100vh - var(--banner-h, 66px) - 34px - var(--dock-h)); display: flex; flex-direction: column; }
#feed { list-style: none; margin: 0; padding: 0; overflow: auto; font-size: 13.5px; display: flex; flex-direction: column-reverse; }
#feed li { padding: 4px 0; border-bottom: 1px solid var(--line); display: flex; gap: 6px; }
#feed li .who { font-weight: 700; }
#feed li.epoch { font-weight: 700; color: var(--lapis-2); }
#feed li.auction { color: var(--ink); }
#feed li.minor { color: var(--muted); }

/* ---- dialogs ---- */
#dialogBack { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
#dialog { background: var(--panel); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); max-width: 640px; width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 18px 20px; }
#dialog h2 { font: 700 22px Georgia, serif; margin-bottom: 8px; }
#dialog .dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.score-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.score-table th, .score-table td { padding: 5px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.score-table th:first-child, .score-table td:first-child { text-align: left; }
.score-table tr.winner-row td { font-weight: 800; background: color-mix(in srgb, var(--gold-2) 22%, transparent); }
.score-table td.neg { color: var(--red); }
.score-table td.tot { font-weight: 800; }
#dialog p.ended { margin: 0 0 10px; padding: 8px 12px; border-radius: 10px; background: var(--panel-2); border-left: 4px solid var(--lapis-2); }
#dialog p.nohints { margin: 6px 0 10px; padding: 8px 12px; border-radius: 10px; font-weight: 650; background: color-mix(in srgb, var(--gold-2) 30%, var(--panel)); border: 1px solid var(--gold); }
.rules h3 { margin: 12px 0 4px; font-size: 15px; } .rules ul { margin: 4px 0; padding-left: 20px; } .rules p { margin: 6px 0; }
.settings label { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.settings input[type=text] { flex: 1; font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); }
.settings select { font: inherit; padding: 4px; border-radius: 8px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.newgame { display: flex; gap: 10px; flex-wrap: wrap; }
.newgame .btn { flex: 1; min-width: 120px; padding: 14px; font-size: 16px; }
pre.history { white-space: pre-wrap; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--panel-2); padding: 10px; border-radius: 10px; max-height: 60vh; overflow: auto; }
#tip { position: fixed; z-index: 70; background: var(--ink); color: var(--panel); font-size: 13.5px; line-height: 1.35; padding: 8px 11px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.3); pointer-events: none; white-space: pre-line; }
#tip::after { content: ''; position: absolute; left: calc(var(--arrow-x, 50%) - 6px); bottom: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: var(--ink); }
#tip.below::after { bottom: auto; top: -6px; border-top: 0; border-bottom: 6px solid var(--ink); }
.tg img, .slot img, .sun { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--dock-h) + 16px); background: var(--ink); color: var(--panel); padding: 8px 16px; border-radius: 999px; z-index: 60; font-size: 14px; box-shadow: var(--shadow); }

/* ---- narrow screens ---- */
@media (max-width: 1100px) {
  #table { grid-template-columns: minmax(250px, 300px) 1fr; }
  #feedPanel { grid-column: 1 / -1; position: static; max-height: 240px; }
}
@media (max-width: 760px) {
  body { font-size: 14px; }
  #top { padding: 6px 10px; gap: 8px; }
  .brand h1 { font-size: 18px; }
  .hdr-actions .ghost { padding: 3px 7px; font-size: 13px; }
  #btnHistory, #btnRules, #btnSettings { display: none; }
  #btnMore { display: inline-block; }
  .track .dot { width: 11px; height: 11px; }
  #banner { padding: 8px 10px; gap: 8px; }
  #prompt { font-size: 15px; }
  .btn { padding: 7px 11px; min-height: 38px; }
  #table { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  #blockPanel, #feedPanel { position: static; }
  .block-row { flex-direction: row; align-items: center; justify-content: center; }
  .slots { grid-template-columns: repeat(4, 54px); gap: 6px; }
  .slot { width: 54px; height: 54px; }
  .sun.big { width: 50px; height: 50px; font-size: 21px; }
  #players { grid-template-columns: 1fr; gap: 8px; }
  .pcard { min-height: 0; padding: 8px 10px; }
  .sun { width: 30px; height: 30px; font-size: 13.5px; }
  .tg, .tg img { width: 30px; height: 30px; }
  .you { gap: 8px 12px; }
  .you .sun { width: 38px; height: 38px; font-size: 15px; }
  .you .tiles { flex-basis: 100%; }
  #feedPanel { max-height: min(320px, 40vh); }
}
