:root {
  --ink: #1b2a3a;
  --paper: #f6ecd6;
  --paper-2: #efe0bf;
  --paper-edge: #b8925a;
  --wood: #6b4524;
  --sea-1: #0b3b5c;
  --sea-2: #11618a;
  --sea-3: #1d8fb3;
  --gold: #e8b23a;
  --correct: #3fa34d;
  --partial: #e3c84a;
  --wrong: #d6453d;
  --muted: #6d5b44;
  --cell: 92px;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  min-height: 100vh;
  background: var(--sea-1);
  overflow-x: hidden;
}

/* animated sea background */
.sea {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255,230,160,.35), transparent 55%),
    linear-gradient(180deg, #7cc4dc 0%, var(--sea-3) 22%, var(--sea-2) 50%, var(--sea-1) 100%);
}
.sea::before, .sea::after {
  content: ""; position: absolute; left: -50%; width: 200%; height: 140px;
  background: repeating-radial-gradient(circle at 50% 100%, rgba(255,255,255,.12) 0 2px, transparent 3px 26px);
  animation: drift 40s linear infinite; opacity: .5;
}
.sea::before { top: 30%; }
.sea::after { top: 62%; animation-duration: 60s; animation-direction: reverse; opacity: .3; }
@keyframes drift { to { transform: translateX(25%); } }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1080px; margin: 0 auto; padding: 18px 16px 6px;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--paper); }
.compass { width: 46px; height: 46px; color: var(--gold); filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); animation: spin 30s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.brand h1 {
  font-family: "Pirata One", "Georgia", serif; font-weight: 400;
  font-size: clamp(34px, 6vw, 56px); margin: 0; letter-spacing: 1px;
  color: var(--paper); text-shadow: 0 3px 0 var(--wood), 0 6px 12px rgba(0,0,0,.35);
}
.brand h1 span { color: var(--gold); }
.top-right { display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--paper-edge);
  background: var(--paper); color: var(--wood); font-weight: 800; font-size: 20px;
  cursor: pointer; display: grid; place-items: center; box-shadow: 0 3px 0 var(--wood);
  transition: transform .1s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood); }

main { max-width: 1080px; margin: 0 auto; padding: 8px 12px 60px; }

/* panels */
.panel {
  background: var(--paper);
  border: 3px solid var(--paper-edge);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--wood), 0 12px 24px rgba(0,0,0,.25);
  max-width: 560px; margin: 14px auto; padding: 16px 18px;
  position: relative;
}
.panel::after {
  content: ""; position: absolute; inset: 5px; border: 1px dashed rgba(107,69,36,.35);
  border-radius: 8px; pointer-events: none;
}
.intro { text-align: center; }
.intro h2 { margin: 2px 0 4px; font-size: 22px; text-transform: uppercase; letter-spacing: .5px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.intro-badges { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 8px; margin-top: 8px; }
.spoiler-pill {
  display: inline-block; font-size: 12px; font-weight: 800;
  background: var(--ink); color: var(--paper); border-radius: 999px; padding: 3px 10px;
  cursor: pointer; position: relative; z-index: 1;
}

/* mode tabs */
.modes { display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.mode {
  font-family: "Pirata One", Georgia, serif; font-size: 22px; letter-spacing: .5px;
  padding: 6px 22px; border-radius: 10px 10px 4px 4px; cursor: pointer;
  border: 2px solid var(--paper-edge); background: rgba(246,236,214,.55); color: var(--ink);
}
.mode.active { background: var(--paper); box-shadow: 0 4px 0 var(--wood); }

/* search */
.search { display: flex; gap: 8px; position: relative; z-index: 5; }
#guess-input {
  flex: 1; font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 8px;
  border: 2px solid var(--paper-edge); background: #fffaf0; color: var(--ink); outline: none;
}
#guess-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,178,58,.3); }
.send {
  width: 52px; border: none; border-radius: 8px; cursor: pointer;
  background: var(--wrong); color: #fff; display: grid; place-items: center;
  box-shadow: 0 3px 0 #8c2a24;
}
.send svg { width: 24px; height: 24px; }
.send:disabled { opacity: .5; cursor: not-allowed; }
.suggestions {
  position: absolute; top: 100%; left: 0; right: 60px; margin: 4px 0 0; padding: 4px;
  list-style: none; background: #fffaf0; border: 2px solid var(--paper-edge); border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0,0,0,.25); max-height: 320px; overflow-y: auto; display: none;
}
.suggestions.open { display: block; }
.suggestions li {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; cursor: pointer;
}
.suggestions li.active, .suggestions li:hover { background: var(--paper-2); }
.suggestions .alias { font-size: 12px; color: var(--muted); }
.guess-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 14px; color: var(--muted); position: relative; z-index: 1; }
.link-btn { background: none; border: none; color: var(--wrong); font: inherit; font-weight: 800; cursor: pointer; text-decoration: underline; }

/* monogram avatar */
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff;
  border: 2px solid rgba(255,255,255,.7); text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.avatar { position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top center; background: #fffaf0; }
.cell.char .avatar { width: 56px; height: 56px; border-color: var(--paper-edge); }
.suggestions .avatar { width: 38px; height: 38px; font-size: 12px; }
.haki-legend { display: flex; justify-content: center; gap: 18px; margin-top: 12px; font-weight: 600; font-size: 14px; position: relative; z-index: 1; }

/* hints */
.hints { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 14px auto; max-width: 720px; }
.hint {
  flex: 1 1 200px; max-width: 230px; background: rgba(246,236,214,.92); border: 2px solid var(--paper-edge);
  border-radius: 10px; padding: 10px 12px; text-align: center; box-shadow: 0 3px 0 var(--wood);
}
.hint h4 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--wood); }
.hint .lock { font-size: 13px; color: var(--muted); }
.hint button {
  font: inherit; font-weight: 800; font-size: 13px; padding: 5px 12px; border-radius: 999px;
  border: 2px solid var(--wood); background: var(--gold); cursor: pointer; color: var(--ink);
}
.hint .reveal { font-weight: 800; font-size: 15px; }
.hint.locked { opacity: .75; }

/* board */
.board-wrap { overflow-x: auto; padding: 4px 0 8px; }
.board { width: max-content; margin: 0 auto; }
.row { display: grid; grid-template-columns: repeat(9, var(--cell)); gap: 6px; margin-bottom: 6px; }
.row.head > div {
  color: var(--paper); font-weight: 800; font-size: 13px; text-transform: uppercase; text-align: center;
  padding: 4px 2px 8px; border-bottom: 4px solid rgba(246,236,214,.75); text-shadow: 0 2px 2px rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.cell {
  height: var(--cell); border-radius: 8px; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 4px; font-weight: 800; font-size: 14px; color: #fff; line-height: 1.15;
  text-shadow: 0 1px 2px rgba(0,0,0,.45); position: relative; overflow: hidden;
  border: 2px solid rgba(0,0,0,.18); word-break: break-word;
  opacity: 0; transform: rotateX(90deg);
}
.cell.show { animation: flip .45s ease forwards; }
@keyframes flip { from { opacity: 0; transform: rotateX(90deg); } to { opacity: 1; transform: rotateX(0); } }
.cell.correct { background: var(--correct); }
.cell.partial { background: var(--partial); color: #3a2f05; text-shadow: none; }
.cell.wrong { background: var(--wrong); }
.cell.small { font-size: 12px; }
.cell.tiny { font-size: 11px; }
.cell .arrow {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  color: rgba(0,0,0,.2); font-size: 70px; line-height: 1;
}
.cell span.v { position: relative; z-index: 1; }
.cell.char { background: var(--paper); color: var(--ink); text-shadow: none; flex-direction: column; gap: 4px; border-color: var(--paper-edge); }
.cell.char .nm { font-size: 11px; line-height: 1.1; }
.cell.char.win { box-shadow: 0 0 0 3px var(--correct) inset; }
.haki { display: flex; gap: 3px; font-size: 22px; text-shadow: none; flex-wrap: wrap; justify-content: center; }

/* legend */
.legend h3 { text-align: center; margin: 0 0 10px; font-size: 18px; }
.legend-items { display: flex; justify-content: space-around; flex-wrap: wrap; gap: 10px; font-weight: 600; font-size: 14px; position: relative; z-index: 1; }
.legend-items > div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sw { width: 40px; height: 40px; border-radius: 6px; display: block; position: relative; }
.sw.correct { background: var(--correct); }
.sw.partial { background: var(--partial); }
.sw.wrong { background: var(--wrong); }
.sw.up::after, .sw.down::after { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(0,0,0,.35); font-size: 30px; }
.sw.up::after { content: "▲"; }
.sw.down::after { content: "▼"; }

.yesterday { text-align: center; color: var(--paper); font-weight: 800; font-size: 18px; text-shadow: 0 2px 3px rgba(0,0,0,.5); }
.yesterday b { color: var(--gold); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(5,20,32,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal {
  background: var(--paper); border: 3px solid var(--paper-edge); border-radius: 14px; max-width: 520px; width: 100%;
  max-height: 88vh; overflow-y: auto; padding: 22px 22px 18px; position: relative; box-shadow: 0 6px 0 var(--wood), 0 20px 40px rgba(0,0,0,.4);
}
.modal h2 { font-family: "Pirata One", Georgia, serif; font-weight: 400; font-size: 32px; margin: 0 0 8px; text-align: center; }
.modal h3 { margin: 16px 0 6px; font-size: 16px; }
.modal p, .modal li { font-size: 15px; line-height: 1.45; }
.modal .close { position: absolute; top: 8px; right: 12px; border: none; background: none; font-size: 30px; cursor: pointer; color: var(--wood); }
.btn {
  font: inherit; font-weight: 800; padding: 10px 18px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--wood); background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 var(--wood);
}
.btn.secondary { background: var(--paper-2); }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.win-card { display: flex; gap: 14px; align-items: center; background: #fffaf0; border: 2px solid var(--paper-edge); border-radius: 10px; padding: 12px; }
.win-card .avatar { width: 64px; height: 64px; font-size: 22px; }
.win-card .nm { font-size: 20px; font-weight: 800; }
.win-card .ep { color: var(--muted); font-size: 14px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-top: 6px; }
.stats-grid b { display: block; font-size: 26px; }
.stats-grid span { font-size: 12px; color: var(--muted); }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 2px solid var(--paper-edge); border-radius: 10px; margin-bottom: 8px; cursor: pointer; background: #fffaf0; }
.radio input { margin-top: 4px; }
.radio small { display: block; color: var(--muted); }
.radio.sel { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,178,58,.3); }
.countdown { text-align: center; font-weight: 800; font-size: 22px; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px; font-weight: 800; z-index: 60; box-shadow: 0 6px 16px rgba(0,0,0,.35);
}
.hidden { display: none !important; }

@media (max-width: 640px) {
  :root { --cell: 74px; }
  .cell { font-size: 12px; }
  .cell.small { font-size: 10.5px; }
  .cell.tiny { font-size: 9.5px; }
  .row.head > div { font-size: 10.5px; }
  .avatar { width: 36px; height: 36px; font-size: 12px; }
  .cell.char .avatar { width: 44px; height: 44px; }
  .haki { font-size: 17px; }
  .brand h1 { font-size: 30px; }
  .compass { width: 32px; height: 32px; }
  .top { padding: 12px 10px 4px; }
  .icon-btn { width: 36px; height: 36px; font-size: 17px; }
  .intro h2 { font-size: 17px; }
  .hints { flex-wrap: nowrap; gap: 6px; }
  .hint { flex: 1 1 0; min-width: 0; padding: 8px 6px; }
  .hint h4 { font-size: 10.5px; }
  .hint .lock, .hint button { font-size: 11px; }
  .hint .reveal { font-size: 12px; }
  .cell .arrow { font-size: 56px; }
}

/* First-visit spoiler picker */
.spoiler-pick { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.spoiler-choice { text-align: left; padding: 14px 16px; border-radius: 10px; border: 2px solid rgba(120, 80, 30, .35);
  background: rgba(255, 255, 255, .55); cursor: pointer; font: inherit; color: inherit; transition: transform .08s, border-color .15s, background .15s; }
.spoiler-choice:hover { border-color: #c8102e; background: rgba(255, 255, 255, .85); transform: translateY(-1px); }
.spoiler-choice b { display: block; font-size: 1.05rem; }
.spoiler-choice small { display: block; opacity: .75; margin-top: 2px; }
#modal-close.hidden { display: none; }

/* ---------- Phone layout ---------- */
/* Keep the Character column pinned while the rest of the board scrolls sideways. */
.row > :first-child { position: sticky; left: 0; z-index: 3; }
.swipe-hint { display: none; text-align: center; color: var(--paper); font-size: 12px; opacity: .85;
  margin: -2px 0 6px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
@media (max-width: 640px) {
  .swipe-hint { display: block; }
  .row.head > :first-child { background: #0d3550; border-radius: 6px 6px 0 0; }
  .board-wrap { -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
  .row > :first-child { box-shadow: 6px 0 8px -4px rgba(0,0,0,.45); }
}
@media (max-width: 480px) {
  :root { --cell: 64px; }
  .row { gap: 4px; margin-bottom: 4px; }
  .cell { font-size: 9.5px; padding: 3px; border-radius: 7px; word-break: normal; overflow-wrap: anywhere; hyphens: auto; }
  .cell.small { font-size: 9px; }
  .cell.tiny { font-size: 8px; }
  .row.head > div { font-size: 9.5px; padding: 2px 1px 6px; }
  .cell.char { gap: 2px; }
  .cell.char .avatar { width: 34px; height: 34px; font-size: 11px; }
  .cell.char .nm { font-size: 8.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .haki { font-size: 13px; gap: 1px; }
  .cell .arrow { font-size: 46px; }
  .brand h1 { font-size: 26px; }
  .intro h2 { font-size: 15px; }
}
.search input { min-width: 0; flex: 1 1 auto; }
.send { flex: 0 0 auto; }
@media (max-width: 480px) { .search input { font-size: 16px; } /* 16px stops iPhones from zooming in on focus */ }

/* Spoiler chooser */
.spoiler-opts { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.spoiler-opts select { display: block; width: 100%; margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  border: 2px solid rgba(120, 80, 30, .35); background: #fffaf0; font: inherit; font-size: 15px; color: inherit; }
#sp-start:disabled { opacity: .5; cursor: not-allowed; }

.aff-shared { display: block; margin-top: 3px; font-size: .85em; font-weight: 600; opacity: .85; line-height: 1.15; }

/* Daily streak badge — colour climbs with the streak */
.streak { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 800; border-radius: 999px;
  padding: 3px 11px 3px 8px; color: #fff; border: 2px solid rgba(0,0,0,.15); cursor: default; transition: background .4s, box-shadow .4s; }
.streak b { font-size: 14px; }
.streak .flame { font-size: 14px; line-height: 1; }
.streak.t0 { background: #8a8f98; color: #f3f3f3; }
.streak.t0 .flame { filter: grayscale(1); opacity: .6; }
.streak.t1 { background: #d9822b; }                                   /* Rookie: orange */
.streak.t2 { background: #d1402f; box-shadow: 0 0 8px rgba(209,64,47,.5); }   /* Supernova: red */
.streak.t3 { background: #7b3fb5; box-shadow: 0 0 10px rgba(123,63,181,.6); } /* Warlord: purple */
.streak.t4 { background: #1f6fd1; box-shadow: 0 0 12px rgba(31,111,209,.7); } /* Emperor: blue */
.streak.t5 { color: #3a2400; border-color: #fff3c4;                           /* Pirate King: shimmering gold */
  background: linear-gradient(110deg, #c8901a 0%, #ffe27a 35%, #fff6cf 50%, #ffe27a 65%, #c8901a 100%);
  background-size: 250% 100%; animation: streak-shine 3s linear infinite; box-shadow: 0 0 14px rgba(255,210,80,.8); }
@keyframes streak-shine { from { background-position: 100% 0; } to { background-position: -150% 0; } }
.streak.pop { animation: streak-pop .7s cubic-bezier(.3,1.6,.5,1); }
.streak.t5.pop { animation: streak-pop .7s cubic-bezier(.3,1.6,.5,1), streak-shine 3s linear infinite; }
@keyframes streak-pop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
@media (max-width: 480px) { .streak .streak-label { font-size: 11px; } }

/* ---------- game tabs ---------- */
.games { display: flex; justify-content: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.game-tab { font: 800 15px Nunito, sans-serif; padding: 8px 16px; border-radius: 999px; border: 2px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.25); color: #fff; cursor: pointer; transition: background .2s; }
.game-tab:hover { background: rgba(0,0,0,.4); }
.game-tab.active { background: var(--gold); color: #3a2400; border-color: #fff3c4; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.stats-game { font-size: 20px; margin: 16px 0 0; text-align: left; }

/* ---------- Jolly Roger game ---------- */
.jr-panel { display: flex; flex-direction: column; align-items: center; }
.jr-frame { width: min(100%, 420px); aspect-ratio: 4 / 3; overflow: hidden; border-radius: 12px; background: #1b1b1b;
  border: 4px solid var(--wood); box-shadow: inset 0 0 18px rgba(0,0,0,.6); position: relative; z-index: 1; }
.jr-frame img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none;
  transition: transform .7s cubic-bezier(.3,.8,.3,1); }
.jr-frame.solved { border-color: var(--correct); }
.jr-zoom { margin: 8px 0 0; font-size: 13px; text-align: center; position: relative; z-index: 1; }
.jr-guesses { display: flex; flex-direction: column; gap: 6px; max-width: 520px; margin: 0 auto 16px; padding: 0 12px; }
.jr-chip { display: flex; align-items: center; gap: 8px; background: var(--wrong); color: #fff; border-radius: 10px; padding: 8px 12px;
  box-shadow: 0 3px 0 rgba(0,0,0,.25); animation: jr-in .35s ease-out; }
.jr-chip.ok { background: var(--correct); }
.jr-chip b { font-size: 15px; }
.jr-chip small { margin-left: auto; opacity: .85; font-size: 12px; text-align: right; }
@keyframes jr-in { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }
.jr-flag-ico { font-size: 22px; width: 36px; text-align: center; flex: none; }
.jr-end { text-align: center; }
.jr-end img { max-width: 100%; max-height: 220px; border-radius: 10px; border: 3px solid var(--wood); background: #1b1b1b; }
.jr-end .nm { font: 800 20px Nunito, sans-serif; margin-top: 8px; }
.jr-end .ep { color: var(--muted); font-size: 14px; }
@media (max-width: 480px) { .game-tab { font-size: 13px; padding: 6px 12px; } .jr-chip small { display: none; } }
