:root {
  --bg-0: #0c0d12;
  --bg-1: #14161e;
  --bg-2: #1d2030;
  --bg-3: #262a3c;
  --line: #353a55;
  --ink: #e6e4d6;
  --ink-dim: #9c9ab0;
  --accent: #c9a24b;
  --accent-2: #5e8a72;
  --danger: #b8523b;
  --warn: #d29030;
  --forest: #3a6b3a;
  --water: #2b6b8a;
  --sky: #6e6e8b;
  --desert: #a07a3a;
  --folklore: #7a3a8a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: 'Iowan Old Style','Palatino Linotype','Georgia',serif; background: var(--bg-0); color: var(--ink); }
button { font-family: inherit; }
.hidden { display: none !important; }

#app {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "bar bar"
    "table side";
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a1c28 0%, #0c0d12 70%);
}

.bar {
  grid-area: bar;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
}
.logo { font-size: 22px; letter-spacing: 4px; color: var(--accent); font-weight: 700; }
.bar-meta { display: flex; gap: 12px; align-items: center; }

.profile-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.profile-chip:hover { border-color: var(--accent); color: var(--accent); }
.profile-chip .profile-icon { font-size: 14px; }
.profile-chip #profile-name { font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-chip .profile-edit { font-size: 11px; opacity: 0.6; }
.profile-chip:hover .profile-edit { opacity: 1; }

#name-modal input {
  width: 100%; padding: 10px 12px; margin: 8px 0;
  background: var(--bg-2); color: var(--ink); font-size: 16px;
  border: 1px solid var(--line); border-radius: 6px; font-family: inherit;
}
#name-modal input:focus { outline: none; border-color: var(--accent); }
.pill { padding: 6px 14px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; font-size: 13px; }
.pill.subtle { color: var(--ink-dim); }

.btn {
  background: var(--accent); color: #1a1408; border: none; padding: 8px 16px; border-radius: 6px;
  font-weight: 700; letter-spacing: 0.5px; cursor: pointer; font-size: 13px;
  transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink-dim); border: 1px solid var(--line); }
.btn.warn { background: var(--warn); color: #1a1408; }

.table {
  grid-area: table;
  display: grid;
  grid-template-rows: 160px 1fr auto;
  padding: 16px 24px;
  gap: 12px;
}

.opponents { display: flex; justify-content: space-around; gap: 12px; }
.opponent {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
}
.opponent .o-name { font-weight: 700; font-size: 15px; }
.opponent .o-meta { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.opponent .o-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; font-size: 11px; }
.opponent .o-stats span { background: var(--bg-2); border: 1px solid var(--line); padding: 2px 6px; border-radius: 4px; }
.opponent .o-handcount { position: absolute; top: 8px; right: 10px; font-size: 11px; color: var(--ink-dim); }
.opponent.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(201,162,75,0.3); }
.opponent .cryptid-tag {
  margin-top: 8px;
  font-size: 11px;
  color: var(--accent);
  background: rgba(201,162,75,0.1);
  border: 1px dashed var(--accent);
  padding: 4px 6px;
  border-radius: 4px;
}

.trick-area {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 200px;
}
.trick-banner {
  position: absolute; top: 12px; left: 16px; right: 16px;
  text-align: center; font-size: 14px; color: var(--ink-dim);
  letter-spacing: 1px;
}
.trick-cards {
  display: flex; gap: 16px; margin-top: 30px;
  flex-wrap: wrap; justify-content: center;
}
.played-card { position: relative; }
.played-card .who {
  position: absolute; top: -18px; left: 0; right: 0; text-align: center;
  font-size: 11px; color: var(--ink-dim);
}
.played-card.winner .card { box-shadow: 0 0 16px var(--accent); border-color: var(--accent); }

.self {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.self-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.self-name { font-weight: 700; color: var(--accent); font-size: 17px; }
.self-stats { display: flex; gap: 14px; }
.stat { display: flex; flex-direction: column; }
.stat-k { font-size: 10px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; }
.stat-v { font-weight: 700; font-size: 16px; }

.hand-row { display: flex; gap: 8px; justify-content: center; min-height: 130px; align-items: flex-start; flex-wrap: wrap; }
.action-row { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 10px; min-height: 38px; }
.bid-controls { display: flex; gap: 8px; align-items: center; }
.bid-controls input { background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 80px; }
#bid-buttons { display: flex; gap: 6px; }
#bid-buttons button {
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-family: inherit;
}
#bid-buttons button:hover { border-color: var(--accent); color: var(--accent); }

.card {
  width: 84px; height: 120px;
  border-radius: 8px;
  background: linear-gradient(160deg, var(--bg-2), var(--bg-3));
  border: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 8px 6px;
  font-size: 12px;
  position: relative;
  cursor: default;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.card.playable { cursor: pointer; }
.card.playable:hover { transform: translateY(-6px); border-color: var(--accent); box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
.card.unplayable { opacity: 0.45; }
.card .top { font-size: 11px; color: var(--ink-dim); display: flex; justify-content: space-between; }
.card .glyph { font-size: 26px; text-align: center; line-height: 1; padding: 4px 0; }
.card .bot { font-size: 11px; color: var(--ink-dim); text-align: center; line-height: 1.2; }
.card.suit-forest { background: linear-gradient(160deg, #1f2e1f, #2a3d2a); border-color: #3a6b3a; }
.card.suit-water { background: linear-gradient(160deg, #1c2a35, #233547); border-color: #2b6b8a; }
.card.suit-sky { background: linear-gradient(160deg, #2a2a35, #353548); border-color: #6e6e8b; }
.card.suit-desert { background: linear-gradient(160deg, #312614, #3f3219); border-color: #a07a3a; }
.card.suit-folklore { background: linear-gradient(160deg, #2a1a35, #392448); border-color: #7a3a8a; }
.card.special { background: linear-gradient(160deg, #1a1a25, #232337); border: 1px dashed var(--accent); }
.card.special .glyph { font-size: 30px; }

.key-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 10px;
  padding: 14px 18px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  max-height: 280px;
  overflow-y: auto;
}
.key-col h4 {
  margin: 0 0 6px 0;
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.key-col h4:not(:first-child) { margin-top: 10px; }
.key-col h4 .hint { color: var(--ink-dim); font-weight: 400; letter-spacing: 0; text-transform: none; font-size: 10px; }
.key-list { margin: 0; padding-left: 18px; color: var(--ink); }
.key-list.compact li { margin-bottom: 3px; }
.key-list li { margin-bottom: 6px; }
.key-list li em { color: var(--warn); font-style: italic; }
.key-list strong { color: var(--ink); }
.key-list .kc {
  display: inline-block;
  min-width: 28px;
  margin-right: 6px;
  text-align: center;
  font-size: 14px;
  line-height: 1;
  vertical-align: middle;
}
.key-list .kc.folklore { color: #c79bd1; }
.key-list .kc.habitat { letter-spacing: 1px; }

.side {
  grid-area: side;
  background: var(--bg-1);
  border-left: 1px solid var(--line);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 14px;
  overflow: hidden;
}
.side-section h3 { margin: 0 0 8px 0; font-size: 12px; letter-spacing: 2px; color: var(--ink-dim); text-transform: uppercase; }
.phase-strip { display: flex; gap: 4px; flex-wrap: wrap; }
.phase-strip .pip {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.phase-strip .pip.done { background: var(--bg-3); color: var(--ink-dim); }
.phase-strip .pip.current { border-color: var(--accent); box-shadow: 0 0 8px rgba(201,162,75,0.5); }
.phase-strip .pip.blood { background: #4a1818; border-color: #b8523b; }

.log-section { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.log {
  flex: 1; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-family: 'SF Mono','Consolas',monospace;
  font-size: 11px; color: var(--ink-dim); line-height: 1.5;
}
.log .ent { margin-bottom: 4px; }
.log .ent.round { color: var(--accent); margin: 6px 0; }
.log .ent.cryptid { color: var(--warn); }
.log .ent.score { color: var(--accent-2); }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-content {
  background: var(--bg-1);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 480px;
  width: 90%;
}
.modal-content h2 { color: var(--accent); margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.hint { color: var(--ink-dim); font-size: 12px; }

.scoreboard { width: 100%; border-collapse: collapse; margin-top: 12px; }
.scoreboard th, .scoreboard td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
.scoreboard th { color: var(--ink-dim); font-weight: 400; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.scoreboard .winner { color: var(--accent); font-weight: 700; }
