/* ── Reset & base ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1c1c1c;
  --surface: #2a2a2a;
  --text: #d4d0c8;
  --muted: #706b63;
  --accent: #c23b22;
  --hearts: #c23b22;
  --diamonds: #d4a030;
  --clubs: #c0c0d0;
  --spades: #4a6fa5;
  --card-bg: #2e2e2e;
  --card-selected: #c23b22;
  --enemy-bg: #1a1020;
  --health-bar: #c23b22;
  --health-bg: #3a3a3a;
}

html, body {
  font-family: 'Courier New', monospace;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
}

/* ── Header ────────────────────────────────────────── */
#header {
  text-align: center;
  position: relative;
}

#header h1 {
  font-size: 1.1rem;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--accent);
}

#settings-btn {
  position: absolute;
  top: 0;
  right: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  font-size: 1.2rem;
  line-height: 1;
}

#settings-btn:active {
  color: var(--text);
}

#settings-menu {
  position: absolute;
  top: 28px;
  right: 0;
  background: var(--surface);
  border: 1px solid #444;
  border-radius: 3px;
  z-index: 10;
  min-width: 140px;
}

#settings-menu.hidden {
  display: none;
}

#settings-menu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  text-align: left;
  cursor: pointer;
}

#settings-menu button:active {
  background: #3a3a3a;
}

/* ── Debug console ────────────────────────────────── */
#debug-console {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50vh;
  background: #111;
  border-top: 2px solid #444;
  z-index: 20;
  display: flex;
  flex-direction: column;
  font-family: 'Courier New', monospace;
}

#debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

#debug-header div {
  display: flex;
  gap: 6px;
}

#debug-header button {
  background: #333;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.65rem;
  padding: 3px 8px;
  border-radius: 2px;
  cursor: pointer;
}

#debug-log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  font-size: 0.6rem;
  line-height: 1.5;
  color: #8a8;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

#info-bar {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Table zone (tavern + enemy + discard) ─────────── */
#table-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0;
}

.pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.pile-card {
  width: 56px;
  height: 80px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: bold;
  border: 3px solid var(--muted);
}

.pile-card.back {
  background: #252540;
  color: var(--text);
  border-color: var(--spades);
}

.pile-card.discard-top {
  background: var(--surface);
  color: var(--muted);
  border-style: dashed;
}

.pile-card.has-cards {
  border-color: var(--text);
  border-style: solid;
}

.pile-card.empty-pile {
  opacity: 0.25;
}

.pile-label {
  font-size: 0.6rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.pile-svg {
  width: 28px;
  height: 28px;
}

.pile-count {
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--text);
}

/* ── Enemy ─────────────────────────────────────────── */
#enemy-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#enemy-card {
  width: 90px;
  height: 126px;
  border-radius: 3px;
  background: var(--enemy-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: bold;
  border: 3px solid var(--muted);
}

#enemy-card.hearts { border-color: var(--hearts); color: var(--hearts); }
#enemy-card.diamonds { border-color: var(--diamonds); color: var(--diamonds); }
#enemy-card.clubs { border-color: var(--clubs); color: var(--clubs); }
#enemy-card.spades { border-color: var(--spades); color: var(--spades); }
#enemy-card.empty { border-color: var(--muted); color: var(--muted); }

#enemy-card.defeated {
  opacity: 0.3;
}

#enemy-stats {
  width: 100%;
  max-width: 200px;
}

#health-bar-wrap {
  position: relative;
  width: 100%;
  height: 18px;
  background: var(--health-bg);
  border-radius: 2px;
  overflow: hidden;
}

#health-bar {
  height: 100%;
  background: var(--health-bar);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 100%;
}

#health-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.65rem;
  font-weight: bold;
}

#enemy-info {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Cheat sheet ───────────────────────────────────── */
#cheat-sheet {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.6rem;
  letter-spacing: 0.5px;
}

.suit-hint {
  white-space: nowrap;
}

.suit-hint.hearts { color: var(--hearts); }
.suit-hint.diamonds { color: var(--diamonds); }
.suit-hint.clubs { color: var(--clubs); }
.suit-hint.spades { color: var(--spades); }

.suit-icon {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  display: inline-block;
}

/* ── Card suit SVG icons ──────────────────────────── */
.card .suit-svg {
  width: 20px;
  height: 20px;
  display: block;
  margin: 0 auto 2px;
}

.card .card-value {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.card .card-value .label {
  font-size: 0.85rem;
  line-height: 1;
}

#enemy-card .suit-svg {
  width: 32px;
  height: 32px;
  display: block;
  margin: 0 auto 4px;
}

#enemy-card .card-value {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#enemy-card .card-value .label {
  font-size: 1.8rem;
  line-height: 1;
}

/* ── Messages ──────────────────────────────────────── */
#message-zone {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 10px;
  background: var(--surface);
  border-radius: 3px;
  border: 1px solid #3a3a3a;
  font-size: 0.7rem;
  line-height: 1.6;
  color: var(--muted);
}

#messages p {
  margin: 2px 0;
}

#messages p:last-child {
  color: var(--text);
}

#messages p.error {
  color: var(--accent);
}

#messages p.separator {
  border-top: 1px solid #3a3a3a;
  margin-top: 4px;
  padding-top: 4px;
  height: 0;
  font-size: 0;
}

#messages p.action {
  color: var(--text);
  font-weight: bold;
}

/* ── Play preview ─────────────────────────────────── */
#play-preview {
  min-height: 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text);
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

#play-preview:empty {
  display: none;
}

#play-preview .preview-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

#play-preview .preview-item .suit-svg {
  width: 12px;
  height: 12px;
  vertical-align: -1px;
}

#play-preview .preview-immune {
  opacity: 0.4;
  text-decoration: line-through;
}

#play-preview .preview-dmg {
  color: var(--accent);
  font-weight: bold;
}

/* ── Hand ──────────────────────────────────────────── */
#hand-zone {
  min-height: 76px;
}

#hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.card {
  width: 48px;
  height: 68px;
  border-radius: 3px;
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: bold;
  border: 3px solid #444;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.card:active {
  transform: scale(0.95);
}

.card.selected {
  border-color: var(--card-selected);
  transform: translateY(-8px);
}

.card.dim {
  opacity: 0.25;
}

.card.hearts { color: var(--hearts); }
.card.diamonds { color: var(--diamonds); }
.card.clubs { color: var(--clubs); }
.card.spades { color: var(--spades); }

/* ── Actions ───────────────────────────────────────── */
#action-zone {
  display: flex;
  gap: 8px;
  padding-bottom: env(safe-area-inset-bottom, 8px);
}

#action-zone button {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 2px;
  cursor: pointer;
}

#action-btn {
  background: var(--accent);
  color: #fff;
}

#action-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

#yield-btn {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--muted);
  flex: 0.4;
}

#yield-btn.hidden {
  display: none;
}

/* ── Game view ────────────────────────────────────── */
#game-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 10px;
}

/* ── Hidden ───────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Main menu ────────────────────────────────────── */
#menu-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 200px;
}

#menu-content h2 {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.menu-btn {
  width: 100%;
  padding: 14px;
  background: var(--surface);
  color: var(--text);
  border: 2px solid #444;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 2px;
  cursor: pointer;
}

.menu-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Lobby ────────────────────────────────────────── */
#lobby-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lobby-content {
  text-align: center;
}

#lobby-content h2 {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 12px;
}

.lobby-count {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 12px;
}

.lobby-players {
  list-style: none;
  margin-bottom: 16px;
}

.lobby-players li {
  font-size: 0.8rem;
  color: var(--text);
  padding: 4px 0;
}

.lobby-invite {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.lobby-invite span {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lobby-invite input {
  background: var(--surface);
  border: 1px solid #444;
  color: var(--text);
  font-family: inherit;
  font-size: 0.7rem;
  padding: 6px 10px;
  border-radius: 3px;
  width: 280px;
  text-align: center;
}

/* ── Other players ────────────────────────────────── */
#other-players {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

#other-players:empty {
  display: none;
}

.other-player {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 2px 8px;
  border: 1px solid #3a3a3a;
  border-radius: 3px;
}

.other-player.active-player {
  color: var(--text);
  border-color: var(--accent);
}

/* ── Turn indicator ───────────────────────────────── */
#turn-indicator {
  text-align: center;
  font-size: 0.75rem;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  min-height: 18px;
}

#turn-indicator:empty {
  display: none;
}

#turn-indicator.your-turn {
  color: var(--accent);
}

#turn-indicator.other-turn {
  color: var(--muted);
}

