:root {
  --bg: #17130f;
  --panel: #211c15;
  --panel-alt: #2a231a;
  --border: #3a3025;
  --text: #e9dfc9;
  --text-muted: #a79980;
  --accent: #d99b3f;
  --accent-dim: #8a6a34;
  --danger: #b3543f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 14px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary { background: transparent; color: var(--text-muted); }

h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.muted { color: var(--text-muted); font-size: 13px; }

/* Topbar */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#topbarLeft, #topbarMid, #topbarRight { display: flex; align-items: center; gap: 12px; }
#gameTitle { font-weight: 700; color: var(--accent); letter-spacing: 0.08em; }
#topbarTribe { font-weight: 600; }
.badge {
  font-size: 11px;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
}
#topbarMid { color: var(--text-muted); font-size: 13px; }

/* App layout */
#app { display: flex; flex: 1; min-height: 0; }

#nav {
  width: 150px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  gap: 4px;
  flex-shrink: 0;
}
.navBtn {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 9px 10px;
  border-radius: 4px;
  color: var(--text);
}
.navBtn:hover:not(.locked) { background: var(--panel-alt); }
.navBtn.active { background: var(--panel-alt); border-color: var(--accent-dim); color: var(--accent); }
.navBtn.locked { color: var(--text-muted); cursor: default; }
.navBtn.locked:hover { border-color: transparent; }

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#mapAndContext {
  flex: 1;
  display: flex;
  min-height: 0;
}

#mapWrap {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  align-items: flex-start;
}

#mapGrid {
  display: grid;
  grid-auto-rows: 46px;
  gap: 3px;
}

.tile {
  width: 46px;
  height: 46px;
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: -2px;
}
.tile:hover { outline-color: rgba(233, 223, 201, 0.5); }
.tile.selected { outline-color: var(--accent); outline-width: 3px; outline-offset: -3px; }
.tile.river::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid rgba(120, 190, 220, 0.55);
  border-radius: 3px;
}
.tileDot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 8px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1a1512;
  font-weight: 700;
}

#context {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}

.infoRow, .popTable tr {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.popTable { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.popTable th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 5px 0; }
.popTable td { text-align: right; padding: 5px 0; }
.popTable tr { border-bottom: 1px solid var(--border); }

#switchSubsistenceBtn { width: 100%; margin-top: 6px; }

.charList { display: flex; flex-direction: column; gap: 8px; }
.charCard {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}
.charName { font-weight: 600; }
.charRole { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.logListFull { display: flex; flex-direction: column; gap: 8px; }
.logEntry { font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.logTime { font-size: 11px; color: var(--accent-dim); }

/* History strip */
#historyStrip {
  height: 120px;
  flex-shrink: 0;
  background: var(--panel-alt);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  overflow-y: auto;
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stripEntry { color: var(--text-muted); }
.stripEntry .logTime { margin-right: 6px; }

/* Decision modal */
#decisionOverlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#decisionOverlay.hidden { display: none; }
.modalBox {
  background: var(--panel);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 22px 26px;
  min-width: 300px;
  max-width: 420px;
}
.modalOptions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.decisionBtn { text-align: left; }
.decisionBtn:hover { background: var(--accent-dim); color: #fff; }

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-alt);
  border: 1px solid var(--accent-dim);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  #mapAndContext { flex-direction: column; overflow-y: auto; }
  #context { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  #nav { flex-direction: row; width: auto; overflow-x: auto; }
}
