:root {
  --bg-dark: #0e1017;
  --bg-panel: #161923;
  --bg-card: #1e2230;
  --bg-hover: #272c3f;
  --border: #2e344b;
  --gold: #d4af37;
  --gold-light: #f0cf65;
  --crimson: #e63946;
  --emerald: #2a9d8f;
  --text-main: #f1f3f9;
  --text-muted: #9aa3bd;
  --font-serif: 'Noto Serif KR', Georgia, serif;
  --font-sans: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(circle at top, #181c2b 0%, var(--bg-dark) 75%);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: rgba(14, 16, 23, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-badge {
  background: linear-gradient(135deg, var(--gold), #a8821c);
  color: #111;
  font-weight: 900;
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  letter-spacing: 0.05em;
}

.app-header h1 {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--gold-light);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.room-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

.room-badge strong {
  color: var(--gold-light);
  letter-spacing: 0.08em;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

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

.btn-xs {
  padding: 0.32rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, #c92a36, var(--crimson));
  color: #fff;
  box-shadow: 0 4px 14px rgba(230, 57, 70, 0.3);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #b89122);
  color: #111;
}
.btn-gold:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-emerald {
  background: linear-gradient(135deg, #2a9d8f, #21867a);
  color: #fff;
}
.btn-emerald:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-danger {
  background: #7f1d1d;
  border: 1px solid #ef4444;
  color: #fecaca;
}
.btn-danger:hover:not(:disabled) {
  background: #991b1b;
}

.btn-ghost {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-outline {
  background: transparent;
  border: 1px dashed var(--gold);
  color: var(--gold-light);
}
.btn-outline:hover:not(:disabled) {
  background: rgba(212, 175, 55, 0.12);
}

/* Screens */
.screen {
  display: none;
  flex: 1;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* Lobby */
.lobby-hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.hero-card {
  max-width: 720px;
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.hero-eyebrow {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  margin-bottom: 0.6rem;
}

.hero-card h2 {
  font-family: var(--font-serif);
  font-size: 1.85rem;
  margin-bottom: 0.8rem;
  line-height: 1.35;
}

.hero-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 2rem;
}

.lobby-form-grid {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"], select, textarea {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.lobby-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

.action-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
}

.action-box h3 {
  font-size: 1.05rem;
  color: var(--gold-light);
}

.action-box p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.join-row {
  display: flex;
  gap: 0.5rem;
}

.join-row input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
}

.divider-vertical {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.status-msg {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--gold-light);
  min-height: 1.4em;
}

/* Waiting Room */
.waiting-container {
  max-width: 980px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.waiting-header {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.badge-tag {
  background: rgba(212, 175, 55, 0.18);
  color: var(--gold-light);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 5px;
}

.gold-text {
  color: var(--gold-light);
}

.sub-text {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.waiting-invite-box {
  display: flex;
  gap: 0.5rem;
  min-width: 280px;
}

.waiting-invite-box input {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.waiting-body {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.25rem;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
}

.panel h3 {
  font-size: 1rem;
  margin-bottom: 0.85rem;
  color: var(--gold-light);
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.panel-title-row h3 {
  margin-bottom: 0;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.char-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.15s ease;
}

.char-card:hover:not(.taken) {
  border-color: var(--gold);
  background: var(--bg-hover);
}

.char-card.selected {
  border-color: var(--gold-light);
  background: rgba(212, 175, 55, 0.14);
}

.char-card.taken {
  opacity: 0.45;
  cursor: not-allowed;
}

.char-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: #111;
}

.char-info strong {
  display: block;
  font-size: 0.92rem;
}

.char-info span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.25rem;
}

.player-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.player-item-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.mini-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(255,255,255,0.5);
}

.center-text {
  text-align: center;
}

/* Game Layout */
.game-layout {
  display: grid;
  grid-template-columns: 290px 1fr 310px;
  gap: 0.9rem;
  padding: 0.9rem;
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.sidebar-left, .sidebar-right {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.compact-panel {
  padding: 0.9rem;
}

.turn-badge {
  background: rgba(42, 157, 143, 0.2);
  color: #6ee7b7;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
}

.game-players-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.gp-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.65rem;
  border-radius: 7px;
  background: var(--bg-card);
  border: 1px solid transparent;
  font-size: 0.83rem;
}

.gp-item.active-turn {
  border-color: var(--gold-light);
  background: rgba(212, 175, 55, 0.14);
}

.gp-item.eliminated {
  opacity: 0.45;
  text-decoration: line-through;
}

/* My Cards */
.my-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
}

.clue-card {
  background: linear-gradient(145deg, #24293a, #191d29);
  border: 1px solid #3a415c;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
}

.clue-card-icon {
  font-size: 1.15rem;
}

.clue-card-type {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.public-cards-box {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
}

.tiny-label {
  font-size: 0.73rem;
  color: var(--gold-light);
  margin-bottom: 0.35rem;
}

.public-cards-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.public-chip {
  background: rgba(212, 175, 55, 0.14);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 5px;
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
}

/* Logs & Chat */
.log-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.9rem;
  min-height: 240px;
}

.game-log-list {
  flex: 1;
  overflow-y: auto;
  max-height: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.25rem;
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
}

.log-entry {
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  background: rgba(255,255,255,0.03);
  line-height: 1.4;
}

.log-entry.system {
  color: var(--gold-light);
  background: rgba(212, 175, 55, 0.08);
}

.log-entry.secret {
  color: #6ee7b7;
  background: rgba(42, 157, 143, 0.16);
  border: 1px solid rgba(42, 157, 143, 0.35);
}

.log-entry.danger {
  color: #fca5a5;
  background: rgba(230, 57, 70, 0.14);
}

.chat-form {
  display: flex;
  gap: 0.4rem;
}

.chat-form input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
}

/* Center Board */
.board-center {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.action-bar {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.turn-banner {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.dice-box {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
}

.die {
  font-size: 1.2rem;
  font-weight: 800;
}

.steps-text {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--gold-light);
}

.turn-instruction {
  font-size: 0.9rem;
  font-weight: 600;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.board-wrapper {
  width: 100%;
  max-width: 660px;
  aspect-ratio: 1 / 1;
  background: #1a1612;
  border: 3px solid #4a3b2c;
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.65);
}

.mansion-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 1px;
  background: #2b241d;
  position: relative;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  font-size: 0.65rem;
}

.cell.hallway {
  background: #d8c7a8;
  border-radius: 2px;
}

.cell.start-spot {
  background: #cbb48c;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}

.cell.room {
  background: #332a24;
  border: none;
}

.cell.room.door {
  background: #5c4632;
  box-shadow: inset 0 0 0 2px #d4af37;
}

.cell.cellar {
  background: #1c1714;
}

.cell.reachable {
  cursor: pointer;
  box-shadow: inset 0 0 0 2px #10b981, 0 0 8px rgba(16, 185, 129, 0.75);
  background-color: rgba(16, 185, 129, 0.38) !important;
  z-index: 4;
}

.cell.reachable:hover {
  background-color: rgba(16, 185, 129, 0.65) !important;
}

.room-label-overlay {
  position: absolute;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 3;
  color: #f4e8d1;
  text-shadow: 0 1px 4px rgba(0,0,0,0.95);
}

.room-label-overlay strong {
  font-family: var(--font-serif);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.room-label-overlay span {
  font-size: 0.62rem;
  color: var(--gold-light);
}

.tokens-holder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1px;
  z-index: 6;
  pointer-events: none;
}

.pawn-token {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid #111;
  box-shadow: 0 2px 5px rgba(0,0,0,0.85);
  transition: transform 0.2s ease;
}

.pawn-token.active-pawn {
  transform: scale(1.28);
  box-shadow: 0 0 0 2px #fff, 0 0 10px #fff;
  z-index: 8;
}

.board-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}
.legend-dot.door { background: #5c4632; border: 1px solid #d4af37; }
.legend-dot.passage { background: var(--gold); }
.legend-dot.reachable { background: #10b981; }

/* Notepad */
.notepad-panel {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.tiny-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.notepad-content {
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.note-section-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--gold-light);
  background: rgba(212, 175, 55, 0.1);
  padding: 0.25rem 0.5rem;
  border-radius: 5px;
  margin-bottom: 0.25rem;
}

.note-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.28rem 0.5rem;
  border-radius: 5px;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.82rem;
  border: 1px solid transparent;
}

.note-row:hover {
  border-color: var(--border);
}

.note-row.state-x {
  opacity: 0.5;
  text-decoration: line-through;
}

.note-row.state-check {
  background: rgba(42, 157, 143, 0.16);
  border-color: rgba(42, 157, 143, 0.4);
}

.note-row.state-star {
  background: rgba(212, 175, 55, 0.16);
  border-color: rgba(212, 175, 55, 0.45);
}

.note-mark {
  font-weight: 700;
  min-width: 24px;
  text-align: center;
}

.memo-box {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.memo-box label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.memo-box textarea {
  font-size: 0.8rem;
  resize: vertical;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 480px;
  width: 100%;
  padding: 1.6rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
}

.modal-card.danger-border {
  border-color: var(--crimson);
}

.modal-card.victory-card {
  border-color: var(--gold);
  text-align: center;
  max-width: 540px;
}

.modal-card.rules-card {
  max-width: 600px;
}

.modal-card h3, .modal-card h2 {
  font-family: var(--font-serif);
  margin-bottom: 0.6rem;
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1.1rem;
}

.warning-text {
  color: #fca5a5;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.3rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.modal-footer.center {
  justify-content: center;
}

.refute-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.refute-option-btn {
  background: var(--bg-card);
  border: 2px solid var(--gold);
  border-radius: 10px;
  padding: 1rem 0.75rem;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  transition: transform 0.15s ease;
}

.refute-option-btn:hover {
  transform: translateY(-2px);
  background: rgba(212, 175, 55, 0.18);
}

.envelope-reveal {
  background: var(--bg-dark);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 1.1rem;
  margin: 1.2rem 0;
}

.envelope-reveal h4 {
  color: var(--gold-light);
  margin-bottom: 0.8rem;
  font-size: 0.95rem;
}

.solution-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.sol-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.rules-body {
  max-height: 60vh;
  overflow-y: auto;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1.2rem;
}

.rules-body h4 {
  color: var(--gold-light);
  margin-top: 0.3rem;
}

.rules-body ul, .rules-body ol {
  padding-left: 1.25rem;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}

.toast {
  background: var(--bg-card);
  border-left: 4px solid var(--gold);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.6);
  font-size: 0.88rem;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 1120px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
  .board-wrapper {
    max-width: 540px;
  }
  .waiting-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .lobby-actions {
    grid-template-columns: 1fr;
  }
  .divider-vertical {
    padding: 0.2rem 0;
  }
  .hero-card {
    padding: 1.5rem;
  }
  .room-label-overlay strong {
    font-size: 0.65rem;
  }
  .pawn-token {
    width: 11px;
    height: 11px;
  }
}
