@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=Caveat:wght@600;700&display=swap');

:root {
  --wood: #2b1d14;
  --wood-dark: #1c120c;
  --felt: #143d31;
  --felt-light: #1c5644;
  --brass: #c89b3c;
  --brass-bright: #e3b94f;
  --chalk: #f2ece0;
  --chalk-dim: #cfc6b4;
  --slate: #24302c;
  --danger: #c65b4e;
  --success: #6fae7f;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--wood-dark);
  color: var(--chalk);
  font-family: 'Inter', sans-serif;
}

.felt-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(227, 185, 79, 0.08), transparent 55%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 6px),
    linear-gradient(160deg, var(--wood) 0%, var(--wood-dark) 100%);
}

h1, h2, h3 { font-family: 'Fraunces', serif; margin: 0; }

.hidden { display: none !important; }

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 6px;
  font-weight: 600;
}

.hint { color: var(--chalk-dim); font-size: 0.85rem; text-align: center; }

.error-text { color: var(--danger); font-size: 0.88rem; min-height: 1.2em; text-align: center; }

/* ---------- Buttons ---------- */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:not(:disabled):hover { transform: translateY(-1px); }
button:not(:disabled):active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(180deg, var(--brass-bright), var(--brass));
  color: #241804;
  padding: 13px 22px;
  font-size: 1rem;
  box-shadow: 0 3px 0 #8a6a24, 0 6px 14px rgba(0,0,0,0.35);
}
.btn-primary:not(:disabled):active { box-shadow: 0 1px 0 #8a6a24; }

.btn-secondary {
  background: var(--felt-light);
  color: var(--chalk);
  padding: 12px 20px;
  font-size: 0.95rem;
  box-shadow: 0 3px 0 #0c2b21, 0 6px 14px rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn-bank {
  background: linear-gradient(180deg, #7fc491, var(--success));
  color: #0e2914;
  padding: 12px 20px;
  font-size: 0.95rem;
  box-shadow: 0 3px 0 #3f7a4c, 0 6px 14px rgba(0,0,0,0.3);
}

/* ---------- Screens ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.landing-card, .lobby-card {
  background: rgba(20, 13, 8, 0.55);
  border: 1px solid rgba(200, 155, 60, 0.25);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  backdrop-filter: blur(6px);
  text-align: center;
}

.wordmark { font-size: 2.6rem; font-weight: 700; color: var(--chalk); }
.wordmark-accent { color: var(--brass-bright); }
.tagline { color: var(--chalk-dim); margin: 8px 0 28px; font-size: 0.95rem; }

.tabs { display: flex; gap: 8px; margin-bottom: 22px; background: rgba(0,0,0,0.25); padding: 4px; border-radius: 12px; }
.tab-btn {
  flex: 1;
  background: transparent;
  color: var(--chalk-dim);
  padding: 10px;
  border-radius: 9px;
  font-size: 0.88rem;
}
.tab-btn.active { background: var(--felt-light); color: var(--chalk); }

.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 0.82rem;
  color: var(--chalk-dim);
  font-weight: 600;
}

input {
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.3);
  color: var(--chalk);
}
input:focus { outline: 2px solid var(--brass); outline-offset: 1px; }

.room-code {
  font-family: 'Caveat', cursive;
  font-size: 4rem;
  color: var(--brass-bright);
  letter-spacing: 0.05em;
  margin: 4px 0 24px;
  line-height: 1;
}

.player-chip-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
}
.player-chip .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); display: inline-block; margin-right: 8px;
}
.player-chip.offline .dot { background: #7a7a7a; }
.player-chip .score { font-family: 'Fraunces', serif; font-weight: 600; color: var(--brass-bright); }

/* ---------- Game screen ---------- */
#screen-game { align-items: stretch; padding: 0; min-height: 100vh; display: grid; grid-template-rows: auto auto 1fr; grid-template-columns: 1fr 280px; gap: 0; }
.scoreboard {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: rgba(0,0,0,0.35);
  border-bottom: 1px solid rgba(200,155,60,0.2);
}
.score-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 8px 16px;
  min-width: 120px;
}
.score-card.active { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass), 0 0 14px rgba(200,155,60,0.35); }
.score-card .name { font-size: 0.78rem; color: var(--chalk-dim); font-weight: 600; }
.score-card .value { font-family: 'Fraunces', serif; font-size: 1.4rem; color: var(--chalk); }
.score-card.offline { opacity: 0.5; }

.banner {
  grid-column: 1 / -1;
  background: linear-gradient(90deg, var(--brass), var(--brass-bright));
  color: #241804;
  text-align: center;
  padding: 8px;
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: 0.02em;
}

.table {
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(255,255,255,0.03), transparent 60%),
    var(--felt);
}

.turn-info { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; justify-content: center; }
.turn-owner { font-family: 'Fraunces', serif; font-size: 1.3rem; }
.turn-score-wrap { display: flex; align-items: baseline; gap: 8px; background: rgba(0,0,0,0.25); padding: 6px 16px; border-radius: 999px; }
.turn-score-label { font-size: 0.75rem; color: var(--chalk-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.turn-score { font-family: 'Fraunces', serif; font-size: 1.5rem; color: var(--brass-bright); }

.dice-tray {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 96px;
  align-items: center;
}

.die {
  width: 74px;
  height: 74px;
  background: linear-gradient(160deg, #fffdf8, #ecdfc4);
  border-radius: 16px;
  box-shadow: 0 4px 0 #b6a578, 0 8px 16px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(0,0,0,0.05);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 12px;
  cursor: default;
  position: relative;
}
.die.clickable { cursor: pointer; }
.die.clickable:hover { transform: translateY(-3px); }
.die .pip {
  width: 11px; height: 11px;
  background: #2b1d14;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  opacity: 0;
}
.die.selected {
  background: linear-gradient(160deg, #fff4d6, var(--brass-bright));
  box-shadow: 0 0 0 3px var(--brass-bright), 0 4px 0 #8a6a24, 0 10px 20px rgba(200,155,60,0.4);
  transform: translateY(-6px);
}
.die.locked {
  background: linear-gradient(160deg, #d8cdb2, #b8ab8a);
  box-shadow: 0 2px 0 #8a7f63, inset 0 0 0 1px rgba(0,0,0,0.08);
  opacity: 0.85;
}
.die.rolling { animation: dice-shake 0.5s ease; }
@keyframes dice-shake {
  0% { transform: rotate(0deg) translate(0,0); }
  20% { transform: rotate(-18deg) translate(-4px,-3px); }
  40% { transform: rotate(14deg) translate(4px,2px); }
  60% { transform: rotate(-10deg) translate(-3px,2px); }
  80% { transform: rotate(8deg) translate(2px,-2px); }
  100% { transform: rotate(0deg) translate(0,0); }
}

/* pip layouts by value, using nth-child position map (1-9 grid cells) */
.die[data-value="1"] .pip:nth-child(5) { opacity: 1; }
.die[data-value="2"] .pip:nth-child(1),
.die[data-value="2"] .pip:nth-child(9) { opacity: 1; }
.die[data-value="3"] .pip:nth-child(1),
.die[data-value="3"] .pip:nth-child(5),
.die[data-value="3"] .pip:nth-child(9) { opacity: 1; }
.die[data-value="4"] .pip:nth-child(1),
.die[data-value="4"] .pip:nth-child(3),
.die[data-value="4"] .pip:nth-child(7),
.die[data-value="4"] .pip:nth-child(9) { opacity: 1; }
.die[data-value="5"] .pip:nth-child(1),
.die[data-value="5"] .pip:nth-child(3),
.die[data-value="5"] .pip:nth-child(5),
.die[data-value="5"] .pip:nth-child(7),
.die[data-value="5"] .pip:nth-child(9) { opacity: 1; }
.die[data-value="6"] .pip:nth-child(1),
.die[data-value="6"] .pip:nth-child(3),
.die[data-value="6"] .pip:nth-child(4),
.die[data-value="6"] .pip:nth-child(6),
.die[data-value="6"] .pip:nth-child(7),
.die[data-value="6"] .pip:nth-child(9) { opacity: 1; }

.set-aside-log { display: flex; flex-direction: column; gap: 4px; align-items: center; min-height: 20px; }
.set-aside-row { font-size: 0.82rem; color: var(--chalk-dim); }
.set-aside-row b { color: var(--brass-bright); }

.flash-message {
  font-family: 'Fraunces', serif;
  font-size: 1.6rem;
  color: var(--danger);
  text-align: center;
  animation: flash-in 0.3s ease;
}
@keyframes flash-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.controls { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.log-panel {
  background: var(--slate);
  border-left: 1px solid rgba(255,255,255,0.06);
  padding: 20px;
  overflow-y: auto;
}
#activity-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
#activity-log li { font-size: 0.82rem; color: var(--chalk-dim); line-height: 1.4; border-left: 2px solid var(--brass); padding-left: 10px; }

@media (max-width: 860px) {
  #screen-game { grid-template-columns: 1fr; }
  .log-panel { border-left: none; border-top: 1px solid rgba(255,255,255,0.06); max-height: 220px; }
  .die { width: 60px; height: 60px; }
}

/* focus visibility */
button:focus-visible, input:focus-visible, .die.clickable:focus-visible {
  outline: 2px solid var(--brass-bright);
  outline-offset: 2px;
}

.leave-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 20;
  background: rgba(0,0,0,0.4);
  color: var(--chalk-dim);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 8px 14px;
  font-size: 0.8rem;
  border-radius: 999px;
}
.leave-btn:hover { color: var(--chalk); border-color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .die.rolling { animation: none; }
  * { transition: none !important; }
}
