:root {
  --bg: #120e0b;
  --panel: #1c1611;
  --panel2: #2a2118;
  --panel3: #342a1f;
  --ink: #f0e6d2;
  --muted: #a89274;
  --gold: #d4a84b;
  --gold-dim: #8a6a2e;
  --accent: #3d6b5a;
  --accent-hi: #4f8a73;
  --danger: #a0453a;
  --line: #3a3026;
  --ok: #6a9a5a;
  --radius: 10px;
  --gap: 0.65rem;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --log-w: 300px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100%; }
#app { min-height: 100%; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; align-items: stretch; justify-content: center; padding: 12px; }
.hidden { display: none !important; }

.panel {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
  width: min(420px, 100%);
  align-self: center;
}
.brand-block { text-align: center; margin-bottom: 1rem; }
.brand-block h1 { margin: .4rem 0 0; font-size: 1.8rem; letter-spacing: .3em; color: var(--gold); }
.brand-block .sub { margin: .2rem 0 0; color: var(--muted); font-size: .85rem; }
.brand-ico { image-rendering: pixelated; border-radius: 8px; border: 1px solid var(--gold-dim); background: #0d0a08; }
.tabs { display: flex; gap: 6px; margin-bottom: 1rem; }
.tab {
  flex: 1; background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: .5rem; border-radius: 6px; cursor: pointer; font: inherit;
}
.tab.active { background: var(--gold-dim); color: var(--ink); border-color: var(--gold); }
.auth-form label { display: block; margin-bottom: .75rem; font-size: .85rem; color: var(--muted); }
.auth-form input, .create-panel input {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem;
  background: #0d0a08; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); font: inherit;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink);
  padding: .55rem 1rem; border-radius: 6px; cursor: pointer; font: inherit; width: 100%;
}
.btn.primary { background: var(--accent); border-color: var(--accent-hi); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { margin-top: .6rem; background: transparent; color: var(--muted); font-size: .85rem; }
.btn.tiny { width: auto; padding: .2rem .55rem; font-size: .75rem; }
.msg { min-height: 1.2em; color: var(--gold); font-size: .85rem; margin: .6rem 0 0; }
.msg.err { color: #e08880; }
.hint { color: var(--muted); font-size: .85rem; }
.class-list { display: flex; flex-direction: column; gap: .5rem; margin: .5rem 0 1rem; }
.class-opt {
  display: block; border: 1px solid var(--line); border-radius: 8px; padding: .7rem .8rem;
  cursor: pointer; background: #0d0a08;
}
.class-opt.selected { border-color: var(--gold); background: #2a2214; }
.class-opt input { margin-right: .5rem; }
.class-opt strong { color: var(--gold); }
.class-opt small { display: block; color: var(--muted); margin-top: .25rem; margin-left: 1.3rem; }

/* ===== Game shell ===== */
#screen-game {
  flex-direction: column;
  padding: 0;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}
#topbar {
  display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  padding: .7rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
#topbar .left { display: flex; align-items: center; gap: .7rem; min-width: 0; }
#hud-portrait { image-rendering: pixelated; border-radius: 6px; border: 1px solid var(--gold-dim); flex-shrink: 0; }
.name-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name-line strong { font-size: 1rem; }
.name-line em { color: var(--gold); font-style: normal; font-size: .85rem; margin-left: .3rem; }
.meta-line { color: var(--muted); font-size: .8rem; }
#topbar .right { display: flex; align-items: center; gap: .45rem; flex-shrink: 0; }
.silver {
  background: #0d0a08; border: 1px solid var(--gold-dim);
  padding: .3rem .7rem; border-radius: 999px; font-size: .85rem;
  display: flex; align-items: baseline; gap: .35rem;
}
.silver-label { color: var(--muted); font-size: .72rem; }
.silver strong { color: var(--gold); font-variant-numeric: tabular-nums; }
.icon-btn {
  position: relative; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { border-color: var(--gold-dim); }
.dot {
  position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%;
  background: #e05555; border: 1px solid #200;
}
.event-banner {
  background: linear-gradient(90deg, #3a2410, #4a3018);
  border-bottom: 1px solid var(--gold-dim);
  color: var(--gold); padding: .5rem 1rem; font-size: .85rem; text-align: center;
}
.tutorial {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  background: #1a2a22; border-bottom: 1px solid var(--accent); padding: .5rem 1rem; font-size: .85rem;
}

.game-body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--log-w);
  min-height: 0;
  align-items: stretch;
}
.game-main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  border-right: 1px solid var(--line);
}
.tabs-main {
  display: flex; gap: 0; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-shrink: 0;
}
.nav-tab {
  flex: 1; background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: .75rem .4rem; cursor: pointer; font: inherit; font-size: .9rem;
}
.nav-tab:hover { color: var(--ink); background: rgba(212,168,75,.06); }
.nav-tab.active { color: var(--gold); border-bottom-color: var(--gold); font-weight: 600; }
#views { flex: 1; padding: 1rem; overflow: auto; }

.view-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: .5rem; margin-bottom: .85rem; flex-wrap: wrap;
}
.view-head h3 { margin: 0; font-size: 1.05rem; letter-spacing: .04em; }
.tick-info { color: var(--muted); font-size: .75rem; }

.goods-list { display: flex; flex-direction: column; gap: .5rem; }
.good-row {
  display: grid; grid-template-columns: 44px 1fr auto auto; gap: .65rem; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .75rem;
  box-shadow: 0 1px 0 rgba(255,255,255,.03) inset;
}
.good-row:hover { border-color: #4a3e32; background: var(--panel2); }
.good-row img { width: 36px; height: 36px; image-rendering: pixelated; border-radius: 4px; }
.good-row .gname { font-weight: 600; }
.good-row .gmeta { color: var(--muted); font-size: .75rem; margin-top: .1rem; }
.good-row .price {
  color: var(--gold); font-variant-numeric: tabular-nums; min-width: 4.8rem;
  text-align: right; font-weight: 600;
}
.good-row .actions { display: flex; gap: .35rem; }
.good-row .actions button {
  border: 1px solid var(--line); background: var(--panel3); color: var(--ink);
  border-radius: 6px; padding: .35rem .6rem; cursor: pointer; font: inherit; font-size: .8rem;
  min-width: 2.4rem;
}
.good-row .actions button.buy { border-color: var(--accent-hi); color: #b8e0c8; }
.good-row .actions button.sell { border-color: var(--gold-dim); color: var(--gold); }
.good-row .actions button:disabled { opacity: .35; cursor: not-allowed; }
.good-row .actions button:not(:disabled):hover { filter: brightness(1.1); }

.travel-layout { display: grid; grid-template-columns: 1fr 240px; gap: .85rem; }
.city-list { display: flex; flex-direction: column; gap: .45rem; max-height: 380px; overflow: auto; }
.city-opt {
  text-align: left; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 10px; padding: .65rem .8rem; cursor: pointer; font: inherit;
}
.city-opt:hover { border-color: #4a3e32; }
.city-opt.selected { border-color: var(--gold); background: #2a2214; }
.city-opt .reg { color: var(--muted); font-size: .75rem; margin-left: .35rem; }
.map-preview {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .75rem;
  display: flex; flex-direction: column; gap: .55rem;
}
.map-title { color: var(--gold); font-size: .85rem; text-align: center; font-weight: 600; }
#asia-map { width: 100%; border-radius: 6px; border: 1px solid #2a2218; }
.map-desc { margin: 0; color: var(--muted); font-size: .75rem; text-align: center; min-height: 2.4em; }
.travel-status {
  margin-top: .9rem; padding: .85rem; background: #1a2a22; border: 1px solid var(--accent);
  border-radius: 10px; text-align: center; line-height: 1.5;
}

.equip-row { display: flex; flex-wrap: wrap; gap: .55rem; }
.equip-item {
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem; width: 76px; font-size: .7rem; color: var(--muted); text-align: center;
}
.equip-item img { width: 32px; height: 32px; image-rendering: pixelated; }
.char-card {
  display: flex; gap: 1rem; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: .9rem;
}
.stat-list { display: flex; flex-direction: column; gap: .45rem; }
.stat-row {
  display: flex; align-items: center; gap: .65rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .75rem;
}
.stat-row .sname { width: 3.5rem; color: var(--gold); font-weight: 600; }
.stat-row .sval { flex: 1; font-variant-numeric: tabular-nums; }
.stat-row button {
  border: 1px solid var(--accent-hi); background: var(--accent); color: #fff;
  border-radius: 6px; width: 30px; height: 30px; cursor: pointer; font: inherit; font-weight: 700;
}
.stat-row button:disabled { opacity: .35; cursor: not-allowed; }

/* ===== Player log ===== */
.player-log {
  display: flex; flex-direction: column; background: #14100c;
  min-height: 0; max-height: calc(100dvh - 56px);
  position: sticky; top: 56px;
}
.log-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: .4rem;
  padding: .65rem .8rem; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-shrink: 0;
}
.log-head h3 { margin: 0; font-size: .9rem; color: var(--gold); letter-spacing: .08em; }
.log-hint { color: var(--muted); font-size: .68rem; }
.log-list {
  flex: 1; overflow-y: auto; padding: .55rem .65rem .9rem;
  display: flex; flex-direction: column; gap: .4rem;
  scrollbar-width: thin; scrollbar-color: var(--gold-dim) transparent;
}
.log-entry {
  font-size: .78rem; line-height: 1.45;
  padding: .45rem .55rem; border-radius: 8px;
  background: var(--panel); border-left: 3px solid var(--line);
  word-break: break-word;
}
.log-entry .log-time {
  display: block; color: var(--muted); font-size: .68rem;
  font-variant-numeric: tabular-nums; margin-bottom: .15rem;
}
.log-entry.type-trade { border-left-color: var(--gold); }
.log-entry.type-travel { border-left-color: var(--accent-hi); }
.log-entry.type-event { border-left-color: #c4783a; background: #241810; }
.log-entry.type-encounter { border-left-color: var(--danger); background: #221410; }
.log-entry.type-stat { border-left-color: #6a8a9a; }
.log-entry.type-system { border-left-color: #6a9a5a; }
.log-entry.type-error { border-left-color: #e08880; color: #e8b8b0; }
.log-entry.type-ui { border-left-color: #4a4038; color: var(--muted); }
.log-empty { color: var(--muted); font-size: .8rem; text-align: center; padding: 1.2rem .5rem; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--gold-dim); border-radius: 12px;
  width: min(420px, 100%); max-height: 80vh; overflow: auto; padding: 1rem;
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.modal-card h2 { margin: 0; font-size: 1.1rem; color: var(--gold); }
#mail-list { list-style: none; margin: 0; padding: 0; }
#mail-list li {
  border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; margin-bottom: .45rem;
  cursor: pointer; background: #0d0a08;
}
#mail-list li.unread { border-color: var(--gold-dim); }
#mail-list .msub { font-weight: 600; }
#mail-list .mfrom { color: var(--muted); font-size: .75rem; }
#mail-list .mbody { margin-top: .4rem; font-size: .85rem; color: var(--ink); display: none; white-space: pre-wrap; }
#mail-list li.open .mbody { display: block; }
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: #2a2214; border: 1px solid var(--gold); color: var(--ink);
  padding: .55rem 1rem; border-radius: 999px; z-index: 60; font-size: .9rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.5); max-width: calc(100vw - 2rem);
}
.qty-row { display: flex; align-items: center; gap: .5rem; margin: .8rem 0; }
.qty-row input {
  width: 5rem; padding: .4rem; background: #0d0a08; border: 1px solid var(--line);
  color: var(--ink); border-radius: 6px; font: inherit; text-align: center;
}

@media (max-width: 860px) {
  .game-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) min(38vh, 280px);
  }
  .game-main { border-right: none; border-bottom: 1px solid var(--line); min-height: 0; }
  .player-log {
    position: relative; top: auto; max-height: none; height: 100%;
    border-top: 1px solid var(--gold-dim);
  }
  #views { padding: .75rem; }
  .travel-layout { grid-template-columns: 1fr; }
  .good-row {
    grid-template-columns: 36px 1fr auto;
    grid-template-areas: "ico name price" "ico name actions";
  }
  .good-row img { grid-area: ico; }
  .good-row > div:nth-child(2) { grid-area: name; }
  .good-row .price { grid-area: price; align-self: end; }
  .good-row .actions { grid-area: actions; justify-self: end; }
}
@media (max-width: 420px) {
  #topbar { padding: .55rem .65rem; }
  .silver-label { display: none; }
  .name-line em { display: none; }
  .nav-tab { font-size: .82rem; padding: .65rem .2rem; }
}
