:root {
  --bg: #0e0a06;
  --panel: #1b140c;
  --tile-a: #2b2117;
  --tile-b: #1a130c;
  --tile-hover-a: #3a2c1d;
  --tile-hover-b: #241a10;
  --gold-l: #d9b96a;
  --gold-d: #6b5122;
  --gold-text: #ffce4f;
  --parchment: #e8dcc0;
  --muted: #a5926f;
  --red: #a61f1f;
  --red-dark: #5c0d0d;
  --cross: #d0342c;
  --line-gold: #ffd24a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 550px at 70% -10%, rgba(160, 110, 40, 0.22) 0%, transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(90, 50, 20, 0.18) 0%, transparent 60%),
    var(--bg);
  color: var(--parchment);
  font-family: "Alegreya", Georgia, "Times New Roman", serif;
  scrollbar-color: #4a3a22 transparent;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 18px 24px 6px;
  max-width: 1100px;
  margin: 0 auto;
}

h1 {
  margin: 0;
  font-family: "Metamorphous", "Alegreya", serif;
  font-size: 27px;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--parchment);
  text-shadow: 0 2px 0 #000, 0 0 22px rgba(255, 190, 70, 0.3);
}
h1 span { color: var(--gold-text); }

.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.online { color: var(--muted); font-size: 13px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online b { color: #7ee29a; }

.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  font-variant: all-small-caps;
  letter-spacing: 0.6px;
  color: var(--parchment);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  background:
    linear-gradient(180deg, var(--tile-a), var(--tile-b)) padding-box,
    linear-gradient(180deg, var(--gold-l), var(--gold-d)) border-box;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 220, 150, 0.12);
  transition: filter 0.12s;
}
.btn:hover:not(:disabled) { filter: brightness(1.25); }
.btn:active:not(:disabled) { filter: brightness(0.9); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  color: var(--gold-text);
  text-shadow: 0 1px 0 #000;
  background:
    linear-gradient(180deg, #8e1b1b, var(--red-dark)) padding-box,
    linear-gradient(180deg, var(--gold-l), var(--gold-d)) border-box;
}
.btn.ghost {
  background:
    linear-gradient(180deg, rgba(43, 33, 23, 0.4), rgba(26, 19, 12, 0.4)) padding-box,
    linear-gradient(180deg, #8a6c33, #4a3617) border-box;
  box-shadow: none;
}
.btn.danger {
  color: #ff9d8f;
  background:
    linear-gradient(180deg, rgba(60, 16, 12, 0.6), rgba(30, 8, 6, 0.6)) padding-box,
    linear-gradient(180deg, #c05045, #5c1f14) border-box;
}

.locked-banner {
  max-width: 1100px;
  margin: 10px auto 0;
  padding: 10px 16px;
  border: 2px solid transparent;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(80, 58, 16, 0.35), rgba(50, 34, 8, 0.35)) padding-box,
    linear-gradient(180deg, var(--gold-l), var(--gold-d)) border-box;
  color: var(--gold-text);
  text-align: center;
  font-weight: 700;
  font-variant: all-small-caps;
  letter-spacing: 1px;
  text-shadow: 0 1px 0 #000;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  max-width: 1100px;
  margin: 16px auto 40px;
  padding: 0 24px;
  align-items: start;
}

/* ---- Board ---- */
.board-frame { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(var(--n, 5), 1fr);
  gap: 8px;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: 8px;
  background:
    linear-gradient(160deg, var(--tile-a), var(--tile-b)) padding-box,
    linear-gradient(160deg, #8a6c33, #4a3617) border-box;
  box-shadow: inset 0 1px 0 rgba(255, 220, 150, 0.08), inset 0 -6px 12px rgba(0, 0, 0, 0.35);
  color: var(--parchment);
  font: inherit;
  font-weight: 500;
  font-size: clamp(9px, 1.35vw, 14px);
  line-height: 1.25;
  cursor: pointer;
  overflow: hidden;
  overflow-wrap: anywhere;
  transition: background 0.15s;
}
.board[data-size="7"] .tile, .board[data-size="8"] .tile { font-size: clamp(8px, 1.1vw, 12px); }

/* Text sits ABOVE the cross (z1) and the bingo lines (z2) */
.tile span {
  position: relative;
  z-index: 3;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
}

button.tile:hover {
  background:
    linear-gradient(160deg, var(--tile-hover-a), var(--tile-hover-b)) padding-box,
    linear-gradient(160deg, var(--gold-l), var(--gold-d)) border-box;
}

.tile.empty {
  cursor: default;
  background: rgba(0, 0, 0, 0.18);
  border: 2px dashed #4a3a22;
  box-shadow: none;
  color: var(--muted);
}

.tile.checked {
  background:
    linear-gradient(160deg, #3a1d13, #22110b) padding-box,
    linear-gradient(160deg, #b0563f, #5c1f14) border-box;
}
.tile.checked span { opacity: 0.9; }
.tile.checked::after {
  content: "✕";
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8em;
  font-weight: 700;
  color: var(--cross);
  opacity: 0.75;
  text-shadow: 0 0 16px rgba(208, 52, 44, 0.7);
}

.board.no-edit .tile { cursor: not-allowed; }
.board.no-edit button.tile:hover {
  background:
    linear-gradient(160deg, var(--tile-a), var(--tile-b)) padding-box,
    linear-gradient(160deg, #8a6c33, #4a3617) border-box;
}
.board.no-edit .tile.checked, .board.no-edit .tile.checked:hover {
  background:
    linear-gradient(160deg, #3a1d13, #22110b) padding-box,
    linear-gradient(160deg, #b0563f, #5c1f14) border-box;
}

#lines {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.bingo-line {
  stroke: var(--line-gold);
  stroke-width: 8;
  stroke-linecap: round;
  opacity: 0.85;
  filter: drop-shadow(0 0 9px rgba(255, 200, 60, 0.85));
}

.bingo-flash {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Metamorphous", "Alegreya", serif;
  font-size: clamp(44px, 9vw, 100px);
  letter-spacing: 8px;
  color: var(--gold-text);
  text-shadow: 0 0 34px rgba(255, 200, 60, 0.95), 0 3px 0 #5c3a00, 0 5px 8px #000;
  pointer-events: none;
  animation: bingo-pop 2.2s ease forwards;
}
@keyframes bingo-pop {
  0% { transform: scale(0.3); opacity: 0; }
  15% { transform: scale(1.15); opacity: 1; }
  30% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- Panel ---- */
.panel {
  border: 2px solid transparent;
  border-radius: 12px;
  background:
    linear-gradient(180deg, #221910, var(--panel)) padding-box,
    linear-gradient(180deg, var(--gold-l), var(--gold-d)) border-box;
  box-shadow: inset 0 1px 0 rgba(255, 220, 150, 0.1), 0 10px 30px rgba(0, 0, 0, 0.5);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sizes { display: flex; gap: 6px; }
.sizes .btn { padding: 5px 9px; font-size: 13px; }
.sizes .btn.current { color: var(--gold-text); filter: brightness(1.15); }

#addForm { display: flex; gap: 8px; }
#addForm input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--gold-d);
  border-radius: 6px;
  color: var(--parchment);
  padding: 8px 12px;
  font: inherit;
  font-size: 14px;
}
#addForm input:focus { outline: none; border-color: var(--gold-l); }
#addForm input::placeholder { color: var(--muted); }

.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.list-head h2 {
  margin: 0;
  font-family: "Metamorphous", "Alegreya", serif;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--gold-text);
  text-shadow: 0 1px 0 #000;
}
.list-head h2 span { color: var(--muted); font-family: "Alegreya", serif; }
.hint { color: var(--muted); font-size: 12px; }

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 46vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.item-list::-webkit-scrollbar { width: 8px; }
.item-list::-webkit-scrollbar-thumb { background: #4a3a22; border-radius: 4px; }
.item-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 13.5px;
}
.item-list li:hover { background: rgba(255, 210, 130, 0.07); }
.item-list .dot { width: 6px; height: 6px; border-radius: 50%; background: #4a3a22; flex: none; }
.item-list .dot.on { background: var(--gold-text); box-shadow: 0 0 6px rgba(255, 200, 60, 0.6); }
.item-list .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item-list .txt.done { text-decoration: line-through; color: var(--muted); }
.item-list .by { color: var(--muted); font-size: 11px; white-space: nowrap; }
.item-list .icon {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 5px;
  visibility: hidden;
}
.item-list li:hover .icon { visibility: visible; }
.item-list .icon:hover { color: var(--parchment); background: rgba(255, 210, 130, 0.12); }
.item-list .icon.del:hover { color: #ff8a7a; }
.empty-list { color: var(--muted); font-size: 13px; text-align: center; padding: 12px 0; font-style: italic; }

.audit summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-variant: all-small-caps;
  letter-spacing: 1px;
  user-select: none;
}
.audit summary:hover { color: var(--parchment); }
.audit ul {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.audit ul::-webkit-scrollbar { width: 8px; }
.audit ul::-webkit-scrollbar-thumb { background: #4a3a22; border-radius: 4px; }
.audit li { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; }
.audit time { flex: none; color: #6e5c3c; font-variant-numeric: tabular-nums; }
.audit b { color: var(--parchment); font-weight: 600; }

/* ---- Modals (parchment, quest-log style) ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 5, 2, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade-in 0.15s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  border: 2px solid transparent;
  border-radius: 10px;
  background:
    linear-gradient(180deg, #efe2c0, #e0cda2) padding-box,
    linear-gradient(180deg, var(--gold-l), var(--gold-d)) border-box;
  padding: 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), inset 0 0 40px rgba(120, 85, 30, 0.15);
  color: #3b2d1a;
}
.modal.danger {
  background:
    linear-gradient(180deg, #efe2c0, #e0cda2) padding-box,
    linear-gradient(180deg, #c05045, #5c1f14) border-box;
}
.modal h3 {
  margin: 0 0 8px;
  font-family: "Metamorphous", "Alegreya", serif;
  font-size: 18px;
  font-weight: 400;
  color: #5c1f14;
}
.modal p { margin: 0 0 14px; color: #5a462c; font-size: 14.5px; line-height: 1.5; }
.modal input {
  width: 100%;
  background: #f6ecd4;
  border: 1px solid #b09a6a;
  border-radius: 6px;
  color: #2c2113;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  margin-bottom: 14px;
}
.modal input:focus { outline: none; border-color: #7a5b26; }
.modal input::placeholder { color: #a08a5e; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal .btn.ghost { color: #5a462c; }

/* ---- Toasts ---- */
#toastRoot {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: #2e0e09;
  border: 1px solid var(--red);
  color: #ff9d8f;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  text-shadow: 0 1px 0 #000;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
  .item-list { max-height: 300px; }
}
