:root {
  --bg: #0e1116;
  --surface: #161b23;
  --surface-2: #1e2530;
  --border: #2a3342;
  --text: #e8ecf2;
  --muted: #93a1b5;
  --accent: #f0b35a;
  --accent-dim: rgba(240, 179, 90, 0.14);
  --nav: #5cc8ff;
  --nav-dim: rgba(92, 200, 255, 0.14);
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #080a0e;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overscroll-behavior: none;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.status-info {
  min-width: 0;
  flex: 1;
}

.room-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-lit {
  background: rgba(240, 179, 90, 0.16);
  color: var(--accent);
}

.badge-dark {
  background: rgba(148, 163, 184, 0.16);
  color: var(--muted);
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.dot {
  opacity: 0.5;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.96);
}

/* Transcript */
.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 20px;
  scroll-behavior: smooth;
  font-family: Georgia, "Charter", "Times New Roman", serif;
  font-size: 1.04rem;
  line-height: 1.56;
}

.turn-entry {
  margin-bottom: 16px;
}

.cmd-pill {
  display: inline-block;
  margin-bottom: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid rgba(240, 179, 90, 0.3);
  color: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
}

.story-text {
  white-space: pre-wrap;
  color: var(--text);
}

.story-banner {
  color: var(--muted);
  font-size: 0.92rem;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 14px;
}

.system-note {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--surface);
  border-left: 3px solid var(--accent);
  padding: 8px 10px;
  border-radius: 6px;
  margin: 8px 0;
}

/* Bottom Control Deck */
.control-deck {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exits-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.exits-strip::-webkit-scrollbar {
  display: none;
}

.exit-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid rgba(92, 200, 255, 0.35);
  background: var(--nav-dim);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.exit-chip .dest {
  color: var(--nav);
  font-weight: 500;
  font-size: 0.78rem;
}

.exit-chip.blocked {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
}

.exit-chip:active {
  transform: scale(0.96);
}

/* Tabs */
.deck-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 11px;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}

.tab-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

.tab-count {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 999px;
}

/* Panels */
.deck-panels {
  max-height: 31dvh;
  overflow-y: auto;
}

.deck-panel {
  display: none;
}

.deck-panel.active {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-content: flex-start;
}

.cmd-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 40px;
  padding: 8px 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  max-width: 100%;
}

.cmd-chip.primary {
  border-color: rgba(240, 179, 90, 0.42);
  background: var(--accent-dim);
}

.cmd-chip .chip-hint {
  font-size: 0.73rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.cmd-chip:active {
  transform: scale(0.97);
}

.empty-state {
  color: var(--muted);
  font-size: 0.84rem;
  padding: 6px 4px;
}

/* Command Builder */
.builder-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.builder-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.86rem;
}

.builder-row-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.builder-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-chip {
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.mini-chip.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

/* Manual Input */
.manual-form {
  display: flex;
  width: 100%;
  gap: 8px;
}

.manual-form input {
  flex: 1;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.send-btn,
.primary-btn,
.secondary-btn,
.danger-btn {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

.send-btn,
.primary-btn {
  background: var(--accent);
  color: #111;
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.danger-btn {
  background: rgba(248, 113, 113, 0.16);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

/* Modals */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 92vw;
  width: 420px;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.close-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.muted {
  color: var(--muted);
  font-size: 0.84rem;
  margin: 0 0 10px;
  line-height: 1.45;
}

.status-msg {
  font-size: 0.82rem;
  color: var(--ok);
  margin: 8px 0 0;
  min-height: 18px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 0.88rem;
}

.game-select-btn {
  border-color: rgba(240, 179, 90, 0.35);
  white-space: nowrap;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60dvh;
  overflow-y: auto;
}

.game-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.game-card.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.game-card:active {
  transform: scale(0.98);
}

.game-card-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.game-card-title {
  font-size: 0.94rem;
  font-weight: 700;
}

.game-card-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(92, 200, 255, 0.14);
  color: var(--nav);
  white-space: nowrap;
}

.game-card-sub {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.game-card-status {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ok);
  margin-top: 2px;
}

.game-card-status.empty {
  color: var(--muted);
  font-weight: 500;
}

@media (max-width: 520px) {
  .app-shell {
    border-left: none;
    border-right: none;
  }

  .top-actions {
    gap: 4px;
  }

  .icon-btn {
    padding: 6px 8px;
  }

  #btn-undo span {
    display: none;
  }
}
