/*
 * 색은 모두 아래 토큰으로만 쓴다. 테마는 <html data-theme="..."> 로 바뀐다 (src/services/theme.ts).
 * 글자색과 바탕색의 대비는 scripts/contrast.py 로 네 테마 모두 확인한다.
 */
:root, [data-theme='cream'] {
  --bg: #efe6d2;            /* 화면 바탕 */
  --surface: #fffaf0;       /* 카드 */
  --surface-2: #f6eedc;     /* 카드 안 목록, 입력 칸 */
  --hover: #efe3c8;
  --text: #2f2316;
  --muted: #65513b;
  --border: #d8c8a6;
  --border-strong: #b49a6c;
  --accent: #8a4a1f;        /* 주 단추, 고른 것 */
  --on-accent: #ffffff;
  --accent-soft: #f3dfb8;   /* 고른 칸의 바탕 */
  --on-accent-soft: #4a2a0e;
  --bar: #3b2a1c;           /* 맨 위 상태 줄, 메뉴 */
  --bar-2: #4a3626;
  --on-bar: #fbf1dc;
  --on-bar-muted: #e2cfae;
  --highlight: #f0b94a;     /* 어두운 줄 위의 강조(금화, 고른 메뉴) */
  --danger: #a3291c;
  --ok: #2e6b22;
  --red-bg: #f7d9d2; --red-fg: #7c1d12;
  --green-bg: #d8ebc8; --green-fg: #245218;
  --gold-bg: #f6e2a8; --gold-fg: #5e420a;
  --scrim: rgba(20, 14, 8, 0.55);
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.08), 0 2px 8px rgba(60, 40, 20, 0.06);
  --focus: #c47a12;
  color-scheme: light;
}
[data-theme='white'] {
  --bg: #f2f3f5; --surface: #ffffff; --surface-2: #f7f8fa; --hover: #eceef2;
  --text: #1d2127; --muted: #59616c; --border: #dcdfe4; --border-strong: #b4bac3;
  --accent: #2f5bd3; --on-accent: #ffffff; --accent-soft: #e3eafc; --on-accent-soft: #1c3a8c;
  --bar: #ffffff; --bar-2: #f2f3f5; --on-bar: #1d2127; --on-bar-muted: #59616c; --highlight: #855b00;
  --danger: #c0261b; --ok: #1f7a32;
  --red-bg: #fde3e0; --red-fg: #a01d13; --green-bg: #dcf3e1; --green-fg: #19632a; --gold-bg: #fbedc4; --gold-fg: #6b4a00;
  --scrim: rgba(15, 20, 30, 0.45); --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 2px 8px rgba(20, 30, 50, 0.06); --focus: #2f5bd3;
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #121417; --surface: #1b1e23; --surface-2: #23272d; --hover: #2c3138;
  --text: #e9ebee; --muted: #a6adb7; --border: #333840; --border-strong: #4c535d;
  --accent: #e2b24e; --on-accent: #1a1406; --accent-soft: #3a3220; --on-accent-soft: #f3d48c;
  --bar: #181b1f; --bar-2: #20242a; --on-bar: #e9ebee; --on-bar-muted: #a6adb7; --highlight: #e8bb57;
  --danger: #ff7b6e; --ok: #7ccf6a;
  --red-bg: #3d2221; --red-fg: #ffb3aa; --green-bg: #1f3520; --green-fg: #a9e29c; --gold-bg: #3a3119; --gold-fg: #f2d38a;
  --scrim: rgba(0, 0, 0, 0.6); --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --focus: #e8bb57;
  color-scheme: dark;
}
[data-theme='navy'] {
  --bg: #0d1729; --surface: #142139; --surface-2: #1a2a47; --hover: #22355a;
  --text: #e6ecf6; --muted: #a9b6cc; --border: #2a3c5f; --border-strong: #3f5682;
  --accent: #f0c04f; --on-accent: #16203a; --accent-soft: #2f3a4a; --on-accent-soft: #f6d98d;
  --bar: #0a1222; --bar-2: #12203a; --on-bar: #e6ecf6; --on-bar-muted: #a9b6cc; --highlight: #f0c04f;
  --danger: #ff8a7d; --ok: #8fd67c;
  --red-bg: #3a2232; --red-fg: #ffb8b0; --green-bg: #1b3530; --green-fg: #a6e3a0; --gold-bg: #34331f; --gold-fg: #f3d78f;
  --scrim: rgba(2, 6, 16, 0.62); --shadow: 0 1px 2px rgba(0, 0, 0, 0.35); --focus: #f0c04f;
  color-scheme: dark;
}

:root {
  --font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', 'Segoe UI', sans-serif;
  --logo: var(--font);
  --radius: 12px;
  --radius-sm: 8px;
  --tab-h: 64px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.55; -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }
#root { height: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; padding: 0; }
.icon { flex: none; display: block; }
.pix { display: inline-block; flex: none; background-repeat: no-repeat; image-rendering: pixelated; vertical-align: middle; }

.shell { position: relative; height: 100%; max-width: 520px; margin: 0 auto; background: var(--bg); overflow: hidden; }
.game { position: relative; height: 100%; display: flex; flex-direction: column; }
.board { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.content { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 14px 28px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* 단추. 이름은 예전 그대로 둔다(wood-btn = 주 단추, .light = 보조 단추) */
.wood-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: 6px 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent); font-weight: 700; text-align: center; line-height: 1.3; transition: filter 0.12s; }
.wood-btn:hover:not(:disabled) { filter: brightness(1.08); }
.wood-btn:active:not(:disabled) { filter: brightness(0.94); }
.wood-btn:disabled { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.wood-btn.light { background: var(--surface); color: var(--text); border-color: var(--border-strong); min-height: 44px; }
.wood-btn.light:hover:not(:disabled) { background: var(--hover); filter: none; }
.wood-btn.light:disabled { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.wood-btn.big { font-size: 18px; min-height: 54px; }
.wood-btn.small { width: auto; min-height: 40px; padding: 4px 12px; font-size: 15px; }
.wood-btn.square { width: 44px; flex: none; padding: 0; }
.wood-btn.choice { align-items: flex-start; text-align: left; padding: 10px 14px; }
.wood-btn.choice span { font-weight: 400; font-size: 14px; opacity: 0.92; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .wood-btn { flex: 1 1 120px; }
.wood-sq { width: 42px; height: 42px; padding: 0; flex: none; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bar-2); color: var(--on-bar); font-weight: 700; font-size: 15px; }
.wood-sq:hover:not(:disabled) { filter: brightness(1.1); }
.wood-sq.on { background: var(--highlight); border-color: var(--highlight); color: var(--bar); }
.wood-sq:disabled { opacity: 0.5; }

/* 맨 위 상태 줄 */
.beam { flex: none; padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--bar); color: var(--on-bar); border-bottom: 1px solid var(--border); }
.beam-row { display: flex; align-items: center; gap: 10px; }
.beam-name, .beam-date { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.beam-name b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.beam-name span, .beam-date span { font-size: 13px; color: var(--on-bar-muted); }
.beam-gold { display: flex; align-items: center; gap: 6px; font-size: 19px; font-weight: 700; color: var(--highlight); font-variant-numeric: tabular-nums; }
.beam-date b { font-size: 19px; font-variant-numeric: tabular-nums; }
.beam-date b span { font-size: 13px; font-weight: 400; }
.speeds { display: flex; gap: 4px; }
.hp { position: relative; flex: 1; min-width: 96px; height: 24px; border-radius: 999px; overflow: hidden; background: #4a1f19; border: 1px solid var(--border-strong); }
.hp i { display: block; height: 100%; background: #c9412f; }
.hp b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.carry { display: flex; gap: 10px; align-items: center; font-variant-numeric: tabular-nums; font-size: 15px; }
.carry span { display: inline-flex; align-items: center; gap: 3px; }
@media (max-width: 380px) { .carry { gap: 6px; } .wood-sq { width: 38px; height: 38px; } }
button.beam-name { border: 0; background: none; padding: 0; text-align: left; color: inherit; }
.beam-who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; text-align: left; color: inherit; cursor: pointer; }
.beam-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.real-clock { font-size: 12px; color: var(--on-bar-muted); font-variant-numeric: tabular-nums; }

/* 제목 카드 (예전 간판) */
.signboard { padding: 16px; display: flex; flex-direction: column; gap: 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--accent); box-shadow: var(--shadow); }
.signboard h1 { font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }
.sign-sub { font-size: 13px; color: var(--muted); line-height: 1.35; }
.title-sign { text-align: center; align-items: center; padding: 28px 18px; border-left-width: 1px; }
.title-sign h1 { font-family: var(--logo); font-size: 30px; font-weight: 800; letter-spacing: 0.02em; }
.title-sign h1 span { color: var(--accent); }
.title-sign p { font-size: 14px; color: var(--muted); }

/* 카드 */
.paper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.paper.event { border-color: var(--danger); border-width: 2px; }
.paper-head { display: flex; flex-direction: column; line-height: 1.3; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.paper-head h2, .dialog h2 { font-size: 18px; }
.paper-head span { font-size: 14px; color: var(--muted); }
.paper-head.with-icon { flex-direction: row; align-items: center; gap: 10px; }
.paper-head.with-icon div { display: flex; flex-direction: column; min-width: 0; }
.sub-head { font-size: 16px; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--border); }
.prose { text-wrap: pretty; }
.note { font-size: 14px; color: var(--muted); }
.note.warn { color: var(--danger); font-weight: 700; }
.note.pad { padding: 10px 12px; }
.note.center { text-align: center; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font-size: 13px; font-style: normal; font-weight: 500; white-space: nowrap; }
.tag.small { margin-left: 6px; min-height: 20px; font-size: 12px; }
.tag.red, .tag.rel-hostile { background: var(--red-bg); border-color: transparent; color: var(--red-fg); }
.tag.green, .tag.rel-alliance { background: var(--green-bg); border-color: transparent; color: var(--green-fg); }
.tag.gold, .tag.rel-rivalry { background: var(--gold-bg); border-color: transparent; color: var(--gold-fg); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.facts.four { grid-template-columns: repeat(4, 1fr); }
.facts div { background: var(--surface-2); padding: 8px 10px; min-width: 0; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.35; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bars.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.bar-head { display: flex; justify-content: space-between; font-size: 14px; }
.bar-head b { font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar-fill { height: 100%; }
.tone-green { background: #5f9a34; } .tone-wood { background: #b06a33; } .tone-stone { background: #8a8791; }
.tone-blue { background: #4f79b8; } .tone-violet { background: #8a5fae; } .tone-gold { background: #d19a2a; }

/* 목록 */
.rows { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden; }
.rows > * + * { border-top: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px; padding: 8px 12px; background: var(--surface-2); border: 0; text-align: left; color: var(--text); }
button.row:not(:disabled):hover { background: var(--hover); }
button.row:disabled { color: var(--muted); }
button.row:disabled .pix { opacity: 0.6; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.row-main b { font-size: 16px; }
.row-main span { font-size: 14px; color: var(--muted); }
.row-main b .tag { margin-left: 4px; min-height: 20px; font-size: 12px; vertical-align: 1px; }
.row-time { font-size: 14px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-price { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; color: var(--muted); white-space: nowrap; line-height: 1.4; font-variant-numeric: tabular-nums; }
.row-price b { font-size: 16px; color: var(--text); }
.row-count { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row.locked .pix { filter: grayscale(1); opacity: 0.7; }
.row.wrap { flex-wrap: wrap; }
.row-btns { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.lock { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); border: 1px solid var(--border-strong); border-radius: 999px; padding: 0 8px; white-space: nowrap; background: var(--surface); }
.mark { width: 22px; height: 22px; margin: 4px; flex: none; border-radius: 5px; border: 1px solid rgba(0, 0, 0, 0.35); }
.t-plains { background: #dde2b0; } .t-forest { background: #a5c597; } .t-mountain { background: #c2bbb0; } .t-riverside { background: #cbe2ab; } .t-lake { background: #badfd2; }
.t-coast { background: #efe3b9; } .t-marsh { background: #b3cab6; } .t-snow { background: #f5f7f8; } .t-desert { background: #ecd19d; }

/* 나눔 단추 (탭 안의 보기 고르기) */
.segments { display: flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.segments button { flex: 1; min-height: 40px; border: 0; border-radius: 7px; background: none; color: var(--muted); font-weight: 700; }
.segments button:hover:not(.on):not(:disabled) { color: var(--text); background: var(--hover); }
.segments button.on { background: var(--accent); color: var(--on-accent); }
.segments button:disabled { opacity: 0.55; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper-value { flex: 1; text-align: center; display: flex; flex-direction: column; line-height: 1.3; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); padding: 3px; }
.stepper-value b { font-size: 19px; } .stepper-value span { font-size: 13px; color: var(--muted); }
.needs, .legs, .checks { list-style: none; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden; }
.needs li, .legs li { display: flex; align-items: center; gap: 8px; padding: 6px 12px; }
.needs li + li, .legs li + li, .checks li + li { border-top: 1px solid var(--border); }
.needs li span { flex: 1; }
.checks li { display: flex; gap: 10px; padding: 7px 12px; align-items: baseline; }
.checks li b { flex: none; width: 2.6em; font-size: 14px; }
.checks li.ok b { color: var(--ok); } .checks li.no b { color: var(--danger); }
.skills { display: flex; flex-direction: column; gap: 10px; }
.group > .row { border: 0; }
.sub { padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.sub h3 { font-size: 14px; color: var(--muted); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { min-height: 36px; padding: 2px 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 14px; }
.pill:hover { background: var(--hover); }
.pill.here { background: var(--accent-soft); color: var(--on-accent-soft); border-color: transparent; }
.ruler { display: flex; flex-direction: column; gap: 10px; }
.ruler-head { display: flex; align-items: center; gap: 10px; }
.ruler-head div { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.ruler-head div span { font-size: 14px; color: var(--muted); }
.crest { width: 28px; height: 34px; flex: none; border: 2px solid rgba(0, 0, 0, 0.45); clip-path: polygon(0 0, 100% 0, 100% 66%, 50% 100%, 0 66%); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.track { height: 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.track-fill { height: 100%; background: var(--accent); }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mode { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); padding: 8px 10px; min-height: 74px; text-align: left; display: flex; flex-direction: column; line-height: 1.35; }
.mode span { font-size: 13px; color: var(--muted); }
.mode.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--on-accent-soft); }
.mode.on span { color: var(--on-accent-soft); }
.mode.off { border-style: dashed; }
.mode.off b { color: var(--muted); }

/* 아래 메뉴 */
.tabbar { flex: none; height: var(--tab-h); display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bar); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { position: relative; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--on-bar-muted); font-size: 12px; }
.tabbar button .pix { opacity: 0.75; }
.tabbar button.on { color: var(--highlight); font-weight: 700; }
.tabbar button.on::before { content: ''; position: absolute; top: 0; left: 24%; right: 24%; height: 3px; border-radius: 0 0 3px 3px; background: var(--highlight); }
.tabbar button.on .pix { opacity: 1; }
.dot-alert { position: absolute; top: 8px; right: 24%; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); border: 2px solid var(--bar); }
.keys { display: none; }

/* 지도: 지도 그림 자체의 색은 테마와 상관없이 그대로 둔다 */
.map-card { position: relative; width: 100%; aspect-ratio: 4 / 5; max-height: 62vh; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: #b9cdd0; box-shadow: var(--shadow); }
.map-card.expanded { position: absolute; inset: 0 0 var(--tab-h) 0; z-index: 20; aspect-ratio: auto; max-height: none; border-radius: 0; }
.map-box { position: absolute; inset: 0; }
.map-svg { display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.map-svg:active { cursor: grabbing; }
.m-region { stroke-width: 0.8; vector-effect: non-scaling-stroke; cursor: pointer; }
.m-region:hover { filter: brightness(0.95); }
.m-shore { fill: none; stroke: #d3e1e2; stroke-width: 9; stroke-linejoin: round; stroke-linecap: round; }
.m-coast { fill: none; stroke: #3a2414; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-inner { fill: none; stroke: rgba(58, 36, 20, 0.16); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-duchy { fill: none; stroke: rgba(58, 36, 20, 0.36); stroke-width: 1.4; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-kingdom { fill: none; stroke: #3a2414; stroke-width: 2.6; stroke-dasharray: 8 5; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-river { fill: none; stroke: #5a9ac0; stroke-width: 2.6; vector-effect: non-scaling-stroke; stroke-linecap: round; pointer-events: none; }
.m-road { fill: none; stroke: #7a5c40; stroke-width: 1.6; stroke-dasharray: 2 5; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-trade { fill: none; stroke: #b0812a; stroke-width: 2.4; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-route { fill: none; stroke: #b23a2e; stroke-width: 4; stroke-dasharray: 3 7; stroke-linecap: square; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-glyph { fill: rgba(58, 36, 20, 0.2); pointer-events: none; }
.m-glyph.line { fill: none; stroke: rgba(58, 36, 20, 0.3); stroke-width: 1.2; }
.m-selected { fill: rgba(255, 255, 255, 0.3); stroke: #b23a2e; stroke-width: 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.m-node, .m-player { pointer-events: none; }
.m-icon { image-rendering: pixelated; overflow: hidden; }
.m-icon image { image-rendering: pixelated; }
.m-dot { fill: #fff5d8; stroke: #3a2414; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.m-label { font-family: var(--font); font-weight: 700; text-anchor: middle; fill: #2a1a0e; stroke: rgba(255, 248, 228, 0.94); paint-order: stroke; stroke-linejoin: round; pointer-events: none; }
.m-label.kingdom { letter-spacing: 0.06em; }
.m-player .pulse { fill: rgba(178, 58, 46, 0.3); transform-box: fill-box; transform-origin: center; animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { from { transform: scale(0.5); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.map-modes { position: absolute; top: 10px; left: 10px; display: flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.map-modes button { border: 0; border-radius: 7px; background: none; min-width: 54px; height: 36px; font-weight: 700; color: var(--muted); }
.map-modes button.on { background: var(--accent); color: var(--on-accent); }
.map-tools { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.map-tools button { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); display: grid; place-items: center; color: var(--text); box-shadow: var(--shadow); }
.map-legend-btn { position: absolute; left: 10px; bottom: 10px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 700; box-shadow: var(--shadow); }
.map-legend { position: absolute; left: 10px; bottom: 56px; right: 10px; max-width: 340px; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; font-size: 13px; box-shadow: var(--shadow); }
.map-legend span { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.map-legend i { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.4); flex: none; }
.map-legend .lg-trade { height: 4px; border: 0; background: #b0812a; }
.map-legend .lg-road { height: 0; border: 0; border-top: 3px dotted #7a5c40; }
.map-legend .lg-me { background: #b23a2e; }

/* 입력 */
.search, .field-row input { display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); }
.field-row input::placeholder, .search input::placeholder { color: var(--muted); opacity: 1; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; min-height: 40px; }
.search:focus-within, .field-row input:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.field-label { font-weight: 700; font-size: 15px; padding: 0; }
.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; min-width: 0; font-size: 16px; }
.origins { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.origins legend { margin-bottom: 6px; }
.origin { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; }
.origin.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--on-accent-soft); }
.origin.on .row-main span { color: var(--on-accent-soft); }
.origin input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.origin:focus-within { outline: 2px solid var(--focus); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; }
.check input { flex: none; width: 20px; height: 20px; accent-color: var(--accent); }
.check:focus-within { outline: 2px solid var(--focus); }
.slot { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; background: var(--surface-2); }
.slot-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.credits { list-style: none; padding-left: 0; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.log { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.log li { border-left: 3px solid var(--border-strong); padding-left: 10px; display: flex; flex-direction: column; gap: 4px; }
.log li.log-event { border-left-color: var(--danger); }
.log li.log-travel { border-left-color: var(--accent); }
.log time { font-size: 13px; color: var(--muted); }
button.link { border: 0; background: none; padding: 4px 2px; color: var(--accent); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
[data-theme='dark'] button.link, [data-theme='navy'] button.link { color: var(--highlight); }
.terms { display: flex; flex-direction: column; gap: 10px; max-height: 260px; overflow-y: auto; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 14px; }
.terms b { display: block; margin-bottom: 2px; }
.terms p + p { margin-top: 4px; }
.terms-date { font-size: 12px; color: var(--muted); }

/* 아래에서 올라오는 창, 대화상자 */
.scrim { position: absolute; inset: 0; z-index: 40; background: var(--scrim); display: flex; align-items: flex-end; animation: fade 0.16s ease-out; }
.scrim.center { align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.scrim.top { z-index: 90; }
.sheet { width: 100%; max-height: 90%; background: var(--surface); color: var(--text); border-radius: 16px 16px 0 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; animation: rise 0.2s ease-out; }
.sheet-scroll { overflow-y: auto; overscroll-behavior: contain; padding: 20px 16px 10px; display: flex; flex-direction: column; gap: 12px; }
.sheet-scroll > * { flex: none; }
.sheet-foot { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.dialog { width: 100%; max-width: 380px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.toast-zone { position: absolute; left: 16px; right: 16px; bottom: calc(var(--tab-h) + 14px); z-index: 60; display: flex; justify-content: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); border-radius: 999px; padding: 8px 16px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); animation: rise 0.18s ease-out; max-width: 100%; }

/* 처음 화면, 첫 장면 */
.title-screen, .intro { height: 100%; overflow-y: auto; padding: 20px 16px 28px; display: flex; flex-direction: column; gap: 14px; }
.intro { justify-content: center; }
.letter { align-items: stretch; text-align: left; }
.letter h1 { font-size: 22px; }
.footnote { font-size: 13px; color: var(--muted); text-align: center; margin-top: auto; padding-top: 8px; }

@media (prefers-reduced-motion: reduce) {
  .scrim, .sheet, .toast, .m-player .pulse { animation: none; }
}

/* 상점 · 영지 · 왕국 · 전투 */
.price-num { min-width: 2.2em; text-align: center; font-size: 18px; font-variant-numeric: tabular-nums; }
.lord { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.lord .btn-row .wood-btn { flex: 1 1 auto; }
.law { display: flex; align-items: center; gap: 10px; }
.law > span { flex: none; width: 3em; font-weight: 700; }
.law .segments { flex: 1; }
.hues { display: flex; gap: 8px; flex-wrap: wrap; }
.hues button { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border); }
.hues button.on { border-color: var(--text); outline: 2px solid var(--focus); outline-offset: 2px; }
.battle .dialog { max-width: 480px; max-height: 96%; overflow-y: auto; }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sides > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.battle-log { list-style: none; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); padding: 8px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; min-height: 5em; }
.commands { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.commands .wood-btn { min-height: 62px; padding: 6px 8px; }
.commands .wood-btn span { font-size: 12px; }

/* 쉬는 시간 고르기 */
.rest-picks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; padding: 6px 4px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); cursor: pointer; }
.pick:hover:not(.on) { background: var(--hover); }
.pick b { font-size: 15px; } .pick span { font-size: 12px; color: var(--muted); }
.pick.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--on-accent-soft); }
.pick.on span { color: var(--on-accent-soft); }

/* 초상화와 설정 단추 */
.portrait { flex: none; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--bar-2); overflow: hidden; }
.portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.portrait.big { width: 84px; height: 84px; border-radius: 14px; background: var(--surface-2); color: var(--muted); font-size: 13px; line-height: 1.3; text-align: center; cursor: pointer; padding: 0; }
.me-head { display: flex; align-items: center; gap: 14px; }
.me-head .paper-head { flex: 1; min-width: 0; }
.wood-sq.gear { flex: none; }
.portrait-edit { align-self: center; width: min(100%, 240px); aspect-ratio: 1; border-radius: 14px; border: 1px solid var(--border-strong); background: #1b1e23; overflow: hidden; }
.portrait-edit canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.portrait-empty { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: #c9ced6; font-size: 14px; }
.portrait-empty img { width: 100%; height: 100%; object-fit: cover; }
.zoom { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.zoom input { flex: 1; min-height: 44px; accent-color: var(--accent); }
.file-btn { position: relative; cursor: pointer; }
.file-btn input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

/* 화면 색 고르기 */
.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.theme-pick { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 4px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font-size: 13px; font-weight: 600; }
.theme-pick:hover:not(.on) { background: var(--hover); }
.theme-pick.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--on-accent-soft); }
.theme-pick i { width: 100%; max-width: 56px; height: 28px; border-radius: 6px; border: 1px solid rgba(127, 127, 127, 0.5); display: flex; overflow: hidden; }
.theme-pick i::before, .theme-pick i::after { content: ''; flex: 1; }
.sw-cream::before { background: #fffaf0; } .sw-cream::after { background: #8a4a1f; }
.sw-white::before { background: #ffffff; } .sw-white::after { background: #2f5bd3; }
.sw-dark::before { background: #1b1e23; } .sw-dark::after { background: #e2b24e; }
.sw-navy::before { background: #142139; } .sw-navy::after { background: #f0c04f; }

/* 넓은 화면(데스크탑): 왼쪽 메뉴 기둥, 가운데 본문, 오른쪽 지도. App.tsx의 WIDE_QUERY와 같은 너비에서 바뀐다. */
@media (min-width: 1024px) {
  :root { --tab-h: 0px; }
  .shell { max-width: 1360px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .title-screen, .intro { align-items: center; }
  .title-screen > *, .intro > * { width: 100%; max-width: 560px; flex: none; }
  .beam { padding: 10px 22px; }
  .game.wide .beam { flex-direction: row; align-items: center; gap: 28px; }
  .game.wide .beam > * { flex: 1 1 0; min-width: 0; }
  .game.wide .beam > .beam-row:first-child { flex: 1.2 1 0; }
  .board { flex-direction: row; }
  .tabbar { order: -1; width: 96px; height: auto; display: flex; flex-direction: column; gap: 4px; border-top: 0; border-right: 1px solid var(--border); padding: 10px 8px; }
  .tabbar button { flex: none; height: 72px; font-size: 13px; border-radius: 10px; }
  .tabbar button.on { background: var(--bar-2); }
  .tabbar button.on::before { top: 18%; bottom: 18%; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
  .tabbar button:hover:not(.on) { background: var(--bar-2); color: var(--on-bar); }
  .keys { display: block; margin-top: auto; padding: 10px 2px; text-align: center; font-size: 12px; line-height: 1.5; color: var(--on-bar-muted); }
  .content { padding: 20px 24px 32px; scrollbar-gutter: stable; }
  .content > * { max-width: 640px; margin-left: auto; margin-right: auto; }
  .side { flex: none; width: clamp(400px, 38vw, 540px); overflow-y: auto; overscroll-behavior: contain; padding: 20px 20px 32px; border-left: 1px solid var(--border); background: var(--surface-2); scrollbar-gutter: stable; }
  .side .map-card { max-height: 58vh; }
  .scrim { align-items: center; justify-content: center; padding: 24px; }
  .sheet { max-width: 560px; max-height: 88%; border-radius: 16px; border: 1px solid var(--border); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); animation: fade 0.16s ease-out; }
  .toast-zone { bottom: 24px; }
  * { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
}

/* 둘러보기: 짚은 곳만 밝게 두고 나머지는 어둡게 가린다 */
.tour { position: fixed; inset: 0; z-index: 80; }
.tour-hole { position: fixed; border-radius: 12px; outline: 2px dashed #ffffff; outline-offset: 3px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.66); transition: left 0.2s, top 0.2s, width 0.2s, height 0.2s; pointer-events: none; }
.tour-dim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.66); }
.tour-card { position: fixed; display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); animation: fade 0.16s ease-out; }
.tour-card h2 { font-size: 17px; }
.tour-card p { font-size: 15px; }
.tour-count { font-size: 12px; font-weight: 700; color: var(--muted); }
.tour-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.tour-actions span { display: flex; gap: 6px; }
@media (prefers-reduced-motion: reduce) { .tour-hole { transition: none; } .tour-card { animation: none; } }

/* 그림: 초상화 · 문장 · 병사 · 건물 · 마을 */
.face { display: block; flex: none; image-rendering: pixelated; background-repeat: no-repeat; object-fit: cover; }
.portrait .face, .portrait.big .face { width: 100%; height: 100%; }
.portrait-empty .face { width: 100% !important; height: 100% !important; }
.faces { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; max-height: 46vh; overflow-y: auto; padding: 2px; }
.face-pick { display: grid; place-items: center; padding: 2px; border: 2px solid transparent; border-radius: 10px; background: var(--surface-2); }
.face-pick:hover { border-color: var(--border-strong); }
.face-pick.on { border-color: var(--accent); background: var(--accent-soft); }
.face-pick .face { border-radius: 7px; }
.crest-img { display: block; flex: none; image-rendering: pixelated; }
.crest-part { display: block; background: var(--text); }
.ruler-head .face, .lord-head .face, .person .face, .row .face { border-radius: 8px; border: 1px solid var(--border); }
.lord-head { display: flex; align-items: center; gap: 10px; }
.person { display: flex; align-items: center; gap: 10px; }
.crest-editor { display: flex; flex-direction: column; gap: 8px; }
.parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 220px; overflow-y: auto; }
.part { min-height: 44px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 13px; }
.part.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--on-accent-soft); }
.part.on .crest-part { background: var(--on-accent-soft); }
.tinctures { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tinctures span { width: 3em; font-weight: 700; font-size: 14px; }
.tinctures button { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border-strong); }
.tinctures button.on { outline: 3px solid var(--focus); outline-offset: 2px; }
.soldier { display: block; flex: none; image-rendering: pixelated; background-repeat: no-repeat; animation: soldier-idle calc(var(--frames) * 0.18s) steps(var(--frames)) infinite; }
.soldier.empty { width: 73px; height: 61px; animation: none; }
@keyframes soldier-idle { from { background-position-x: 0; } to { background-position-x: var(--end); } }
.building { display: block; flex: none; image-rendering: pixelated; background-repeat: no-repeat; }
.townscape { display: block; flex: none; background-repeat: no-repeat; }
.signboard.with-art { flex-direction: row; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; }
.sign-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
@media (prefers-reduced-motion: reduce) { .soldier { animation: none; } }

/* 대화 */
.tabbar { grid-template-columns: repeat(6, 1fr); }
.tabbar button .icon { color: inherit; opacity: 0.85; }
.chat { display: flex; flex-direction: column; gap: 10px; height: 100%; min-height: 420px; }
.chat-list { list-style: none; flex: 1; min-height: 240px; max-height: calc(100vh - 380px); overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.chat-line { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); max-width: 92%; }
.chat-line.mine { align-self: flex-end; background: var(--accent-soft); color: var(--on-accent-soft); }
.chat-line.mine .chat-meta span, .chat-line.mine .chat-meta time { color: var(--on-accent-soft); }
.chat-line p { overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-meta { display: flex; align-items: baseline; gap: 6px; font-size: 13px; flex-wrap: wrap; }
.chat-meta span, .chat-meta time { color: var(--muted); }
.chat-meta .link { margin-left: auto; font-size: 12px; padding: 0 2px; }
.chat-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 20px 0; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; min-height: 46px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font-size: 16px; }
.chat-form input::placeholder { color: var(--muted); opacity: 1; }
.chat-form .wood-btn { width: auto; }
@media (min-width: 1024px) { .chat-list { max-height: calc(100vh - 330px); } }
