:root {
  --paper: #f3eee4;
  --ink: #2a2622;
  --muted: #6f675e;
  --line: rgba(42, 38, 34, 0.12);
  --gold: #9a6b24;
  --danger: #b2402f;
  --city: #d24b3a;
  --farm: #e6b422;
  --forest: #8a6a3c;
  --sawmill: #2f9e8f;
  --port: #46618c;
}

* {
  box-sizing: border-box;
}

/* .gate와 label에 display를 주면 hidden 속성이 먹지 않는다. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Noto Sans KR", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

#map {
  position: fixed;
  inset: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}

#map.dragging {
  cursor: grabbing;
}

#map.building {
  cursor: crosshair;
}

/* 로그인 전 화면 */
.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr minmax(360px, 30vw);
  background: var(--paper);
  overflow: auto;
}

.gate-art {
  overflow: hidden;
  border-right: 1px solid var(--line);
}

.gate-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gate-panel {
  padding: 48px 40px;
  align-self: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.gate-panel h1 {
  margin: 0;
  font-family: "Gowun Batang", serif;
  font-size: clamp(2.6rem, 5vw, 3.6rem);
  line-height: 1;
}

.lede {
  margin: 14px 0 26px;
  color: var(--muted);
  line-height: 1.7;
  font-size: 0.96rem;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 16px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.tab.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  font-size: 0.82rem;
  color: var(--muted);
}

input {
  font: inherit;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

button[type="submit"] {
  margin-top: 4px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

button[type="submit"]:disabled {
  opacity: 0.55;
  cursor: progress;
}

.error {
  margin: 0;
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.86rem;
}

.fine {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

/* 지도 위 표시 */
.hud,
.legend,
.tools,
.board {
  position: fixed;
  z-index: 5;
  background: rgba(243, 238, 228, 0.93);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  backdrop-filter: blur(6px);
}

.hud {
  top: 18px;
  left: 18px;
  min-width: 250px;
}

.hud-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud h1 {
  margin: 0;
  flex: 1;
  font-family: "Gowun Batang", serif;
  font-size: 1.4rem;
  line-height: 1.2;
}

/* 돈이 바닥나 열차가 선 회사 */
.hud.halted {
  border-color: var(--danger);
}

.hud.halted .figures dd {
  color: var(--danger);
}

.company-color {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  background: var(--city);
}

#logout {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 11px;
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
}

.figures {
  display: flex;
  gap: 18px;
  margin: 14px 0 0;
}

.figures div {
  display: grid;
  gap: 2px;
}

.figures dt {
  color: var(--muted);
  font-size: 0.74rem;
}

.figures dd {
  margin: 0;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.status {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.legend {
  bottom: 18px;
  left: 18px;
  font-size: 0.82rem;
}

.legend ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--muted);
}

.swatch.city {
  background: var(--city);
}
.swatch.farm {
  background: var(--farm);
}
.swatch.forest {
  background: var(--forest);
}
.swatch.sawmill {
  background: var(--sawmill);
}
.swatch.port {
  background: var(--port);
}
.swatch.start {
  background: transparent;
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
}

/* 도구 막대 */
.tools {
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 12px;
  text-align: center;
}

.tool-row {
  display: flex;
  gap: 6px;
}

.tool {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 15px;
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
}

.tool.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.tool kbd {
  font: inherit;
  font-size: 0.68rem;
  opacity: 0.6;
}

.tool-note {
  margin: 9px 0 1px;
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.tool-note.warn {
  color: var(--danger);
}

/* 오른쪽 판. 내 역, 구간, 열차 */
.board {
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: 280px;
  padding: 14px 16px;
  overflow-y: auto;
  display: grid;
  gap: 16px;
  align-content: start;
  font-size: 0.82rem;
}

.board h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.board h2 .buy {
  margin-left: auto;
}

.board h2 b {
  font-weight: 500;
  color: var(--ink);
}

.rows {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 5px;
}

.rows li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.5);
}

.rows .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rows .num {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.rows .empty {
  border: none;
  background: none;
  color: var(--muted);
  padding: 0;
}

.rows i.dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}

.mini {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 9px;
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  flex: none;
}

.mini:hover {
  border-color: var(--ink);
  color: var(--ink);
}

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

/* 열차 줄은 펼치면 칸과 노선을 고칠 수 있다. */
.rows li.train {
  display: grid;
  gap: 7px;
}

.train-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.state {
  flex: none;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.68rem;
  background: rgba(42, 38, 34, 0.08);
  color: var(--muted);
}

.state.moving {
  background: var(--sawmill);
  color: #fff;
}

.state.waiting,
.state.stopped {
  background: var(--danger);
  color: #fff;
}

.bar {
  height: 3px;
  border-radius: 2px;
  background: rgba(42, 38, 34, 0.1);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--ink);
}

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

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.chip i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--muted);
}

.detail {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.detail h3 {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
}

.detail select {
  font: inherit;
  font-size: 0.76rem;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}

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

/* 좁은 화면에서는 도구 막대와 겹치므로 범례를 접는다. */
@media (max-width: 880px), (max-height: 620px) {
  .legend {
    display: none;
  }
}

@media (max-width: 720px) {
  .board {
    display: none;
  }
}

@media (max-width: 860px) {
  .gate {
    grid-template-columns: 1fr;
  }

  .gate-art {
    height: 32vh;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .gate-panel {
    padding: 28px 22px 40px;
  }
}
