:root {
  color-scheme: dark;
  --bg: #101113;
  --side: #141518;
  --panel: #191a1e;
  --raised: #202126;
  --border: #2b2d33;
  --text: #f3f2ef;
  --muted: #a0a2ad;
  --gold: #e3b769;
  --gold-hover: #f2c87c;
  --green: #7bd5ad;
  --red: #fc9999;
  --sidebar-width: 230px;
  --mobile-nav: 65px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", sans-serif;
  font-variant-numeric: tabular-nums;
  text-rendering: optimizeLegibility;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 1rem; }
a { color: inherit; text-decoration: none; }
button, summary, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
p, h1, h2, h3, dl, dd, ul { margin: 0; }
svg, img { display: block; flex: none; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.gold { color: var(--gold); }
.muted { color: var(--muted); }

.shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--side); border-right: 1px solid var(--border); padding: 27px 18px 20px; }
.brand, .mobile-brand { align-items: center; gap: 11px; }
.brand { display: flex; padding: 0 7px; width: fit-content; }
.brand img, .mobile-brand img { border: 1px solid #5d492d; border-radius: 11px; background: #2c251b; }
.brand strong, .mobile-brand strong { display: block; color: #f5f4ef; font-size: 1.35rem; font-weight: 790; letter-spacing: .10em; line-height: 1.1; }
.brand-period { color: var(--gold); }
.brand small { display: block; margin-top: 5px; color: var(--muted); font-size: .73rem; white-space: nowrap; }
.mobile-brand { display: none; }
.navigation { display: grid; gap: 5px; margin-top: 51px; }
.nav-caption { color: #898b95; font-size: .76rem; font-weight: 650; padding: 0 12px 9px; letter-spacing: .05em; }
.nav-link { position: relative; display: flex; align-items: center; gap: 11px; min-height: 47px; padding: 0 12px; border: 1px solid transparent; border-radius: 8px; color: #b0b2bc; font-size: .91rem; font-weight: 590; }
.nav-link:hover { background: #1d1e23; color: var(--text); }
.nav-link[aria-current="page"] { border-color: #4c3d2a; background: #2b241a; color: #ebbd70; }
.sidebar-footer { margin-top: auto; padding: 0 7px; }
.save-indicator, .build { display: flex; align-items: center; color: var(--muted); font-size: .76rem; }
.save-indicator { min-height: 43px; gap: 8px; border-bottom: 1px solid var(--border); }
.save-indicator i, .health i { width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }
.save-indicator i { color: var(--green); }
.save-warning i { color: var(--red); }
.build { justify-content: space-between; padding-top: 14px; color: #898b95; }

.workspace { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 0 clamp(22px, 2.75vw, 42px); min-height: 73px; border-bottom: 1px solid #26272c; background: #131416; }
.crumb { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .87rem; }
.crumb strong { color: #e9e8e6; font-weight: 630; }
.crumb-divider { color: #626570; }
.turn-controls, .calendar { display: flex; align-items: center; }
.turn-controls { gap: 14px; }
.calendar { min-height: 42px; gap: 8px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: #191a1e; color: #dedee3; font-size: .87rem; font-weight: 640; white-space: nowrap; }
.calendar svg { color: #a7a8b1; }

main { max-width: 1600px; margin-inline: auto; padding: 34px clamp(22px, 2.75vw, 42px) 44px; }
main:focus { outline: none; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 25px; }
h1 { font-size: clamp(1.66rem, 2.25vw, 2.13rem); font-weight: 750; letter-spacing: -.045em; line-height: 1.22; }
.page-heading p { color: var(--muted); margin-top: 9px; font-size: .94rem; line-height: 1.55; }
.health { display: flex; flex: none; align-items: center; gap: 7px; margin-bottom: 3px; padding: 6px 10px; background: #1c2522; border: 1px solid #2c4239; border-radius: 30px; font-size: .77rem; font-weight: 650; }
.health.negative { background: #302022; border-color: #4e3438; }
.health.gold { background: #2d2519; border-color: #4c3d2a; }
.health i { width: 6px; height: 6px; }

.button { display: inline-flex; justify-content: center; align-items: center; gap: 7px; min-height: 44px; padding: 0 14px; color: var(--text); background: #222329; border: 1px solid #373942; border-radius: 8px; font-size: .87rem; font-weight: 670; white-space: nowrap; }
.button:hover:enabled { background: #2b2d35; border-color: #4b4e59; }
.button.primary { color: #21170a; background: var(--gold); border-color: #efc479; box-shadow: 0 2px 8px #0003, inset 0 1px #fff3; }
.button.primary:hover:enabled { background: var(--gold-hover); border-color: var(--gold-hover); }
.button.gold-outline { background: #2a241b; color: #edc580; border-color: #56452e; }
.button.gold-outline:hover:enabled { background: #3a2f20; border-color: #806640; }
.button.danger { background: #2e2024; color: var(--red); border-color: #58323b; }
.button.danger:hover:enabled { background: #40262e; border-color: #884e5b; }

.panel { min-width: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 13px; box-shadow: 0 3px 12px #07080a19; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.stat-card { min-height: 132px; padding: 15px 17px 16px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #b9bac2; font-size: .89rem; font-weight: 600; }
.stat-value { margin-top: 6px; font-size: clamp(1.22rem, 2vw, 1.79rem); font-weight: 740; letter-spacing: -.038em; overflow-wrap: anywhere; line-height: 1.15; }
.stat-caption { margin-top: 9px; color: var(--muted); font-size: .77rem; }
.icon-tile { display: grid; flex: none; place-items: center; width: 38px; height: 38px; border-radius: 8px; border: 1px solid #393b44; background: #272930; color: #b6b8c3; }
.icon-tile.amber { color: #e9ba72; border-color: #4d3c29; background: #32281c; }
.icon-tile.green { color: #82d6ac; border-color: #30493d; background: #203329; }
.icon-tile.red { color: #ee9698; border-color: #4e363b; background: #352529; }
.icon-tile.blue { color: #9cbafb; border-color: #35425d; background: #252e42; }
.icon-tile.violet { color: #bea8fb; border-color: #433950; background: #30263e; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.98fr) minmax(260px, 1fr); align-items: start; gap: 16px; margin-top: 18px; }
.overview-grid + .panel { margin-top: 18px; }
.dashboard-grid > .business-panel { grid-column: 1 / -1; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.panel h2, .modal-header h2 { font-size: 1.13rem; font-weight: 720; letter-spacing: -.025em; }
.panel-heading p, .modal-header p { color: var(--muted); font-size: .82rem; margin-top: 6px; line-height: 1.5; }
.chart-panel, .market-panel, .summary-panel, .business-panel, .settings-panel, .ledger-panel { padding: 19px 20px; }
.chart-summary { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-top: 18px; }
.chart-summary strong { color: var(--gold); font-size: 1.61rem; font-weight: 740; letter-spacing: -.04em; overflow-wrap: anywhere; }
.chart-summary span { color: var(--muted); font-size: .78rem; }
.segmented { display: flex; flex: none; gap: 3px; padding: 3px; background: #121315; border: 1px solid #2d2f36; border-radius: 8px; }
.segmented button { min-height: 36px; padding: 0 9px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: #a8aab5; font-size: .78rem; font-weight: 650; white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: #292a31; color: #f2f1ef; border-color: #3b3d47; }
#growth-chart { display: block; width: 100%; height: 192px; margin-top: 10px; }
.chart-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 5px 11px; margin-top: 9px; color: var(--muted); font-size: .76rem; }
.legend, .legend span { display: flex; align-items: center; gap: 6px; }
.legend { gap: 13px; }
.legend i { display: block; width: 17px; border-top: 2px solid var(--gold); }
.legend i.dashed { border-top-style: dashed; }
.chart-data { margin-top: 6px; color: var(--muted); font-size: .77rem; }
.chart-data summary { width: fit-content; min-height: 38px; padding: 10px 0 8px; cursor: pointer; }
.chart-data table { white-space: normal; }
.market-panel, .summary-panel { display: flex; flex-direction: column; min-height: 390px; }
.market-date { display: grid; place-items: center; min-height: 30px; padding: 0 10px; border: 1px solid #3a3b44; border-radius: 6px; background: #23242a; color: #c3c4cc; font-size: .76rem; white-space: nowrap; }
.market-list { padding: 0; margin: 13px 0 16px; list-style: none; }
.market-list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; min-height: 68px; border-bottom: 1px solid #2c2e34; }
.market-list li:last-child { border: 0; }
.market-list strong, .business-row strong, .empty-state strong, .setting-row strong { display: block; font-size: .9rem; }
.market-list small, .business-row span:not(.icon-tile), .business-profit small { display: block; color: var(--muted); margin-top: 4px; font-size: .75rem; }
.market-delta { margin-left: auto; font-size: .85rem; font-weight: 720; }
.market-note { display: flex; align-items: flex-start; gap: 7px; margin-top: auto; padding: 10px; border: 1px solid #31333b; border-radius: 7px; background: #202127; color: #aeb0ba; font-size: .76rem; line-height: 1.55; word-break: keep-all; overflow-wrap: anywhere; }
.market-note svg { margin-top: 1px; }
.business-panel .panel-heading, .ledger-panel .panel-heading { align-items: center; }
.count-pill { display: inline-grid; place-items: center; padding: 1px 6px; min-width: 23px; border-radius: 6px; border: 1px solid #383b44; color: #bcbec9; background: #24262d; font-size: .74rem; vertical-align: 2px; margin-left: 4px; }
.empty-state { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 78px; margin-top: 17px; padding: 11px; background: #16171a; border: 1px dashed #34363e; border-radius: 9px; }
.empty-state p, .setting-row p { color: var(--muted); font-size: .82rem; margin-top: 4px; line-height: 1.5; }
.business-list { display: grid; gap: 8px; margin-top: 17px; }
.business-row { display: grid; align-items: center; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 12px; padding: 10px; background: #16171a; border: 1px solid #2b2d33; border-radius: 8px; }
.business-profit { text-align: right; margin-right: 5px; }
.business-profit small { margin: 0 0 4px; }
.business-profit strong { overflow-wrap: anywhere; }
.warning { display: flex; align-items: center; gap: 11px; min-height: 68px; padding: 10px 14px; margin-bottom: 15px; border-radius: 9px; background: #2e2024; color: #ffc2c2; border: 1px solid #573842; }
.warning.caution { color: #edcd91; background: #2d261a; border-color: #59472e; }
.warning p { font-size: .82rem; margin-top: 4px; }
.warning .button { margin-left: auto; }

.ledger { display: grid; gap: 0; margin: 15px 0; }
.ledger > div, .compact-ledger > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ledger > div { padding: 9px 0; border-bottom: 1px solid var(--border); }
.ledger dt, .compact-ledger dt { color: var(--muted); font-size: .85rem; }
.ledger dd, .compact-ledger dd { font-weight: 670; white-space: nowrap; }
.table-scroll { overflow: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; text-align: right; white-space: nowrap; font-size: .81rem; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--border); }
th:first-child { text-align: left; }
thead th { color: var(--muted); background: #1e2025; font-weight: 620; }
tbody th { font-weight: 610; }
.empty-note { margin-top: 17px; padding: 13px 0; color: var(--muted); font-size: .88rem; }
.settings-panel + .settings-panel { margin-top: 15px; }
.setting-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: 0; padding-bottom: 0; }
.settings-panel .panel-heading { margin-bottom: 6px; }

dialog { width: min(590px, calc(100% - 28px)); max-height: 88vh; max-height: 88dvh; padding: 0; background: #1b1c20; color: var(--text); border: 1px solid #393b44; border-radius: 14px; box-shadow: 0 20px 60px #0009; }
dialog::backdrop { background: #07080bc9; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 19px 20px; border-bottom: 1px solid var(--border); }
.icon-button { display: grid; flex: none; place-items: center; width: 44px; height: 44px; border: 1px solid #3a3d45; border-radius: 8px; color: var(--muted); background: #222329; }
.icon-button:hover { color: var(--text); }
.sector-options, .manage-body, .install-list, .modal-buttons { padding: 16px 20px 20px; }
.sector-options { display: grid; gap: 9px; }
.sector-option { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 10px; border: 1px solid var(--border); border-radius: 9px; padding: 11px; background: #202126; }
.sector-option h3 { font-size: .98rem; }
.sector-option p, .install-list p { margin-top: 4px; color: var(--muted); font-size: .82rem; line-height: 1.5; }
.compact-ledger { display: grid; gap: 4px; margin: 9px 0; }
.compact-ledger dd { font-size: .86rem; }
.manage-body .ledger { margin: 0 0 13px; }
.action-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 0; }
.action-row strong, .action-row small { display: block; }
.action-row strong { font-size: .9rem; }
.action-row small { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; }
.install-list { list-style: none; }
.install-list li + li { margin-top: 12px; }
.dialog-feedback { padding: 10px 20px 0; font-size: .85rem; }
#notice { position: fixed; z-index: 3; bottom: 21px; right: 24px; max-width: min(460px, calc(100% - 48px)); padding: 11px 14px; border: 1px solid #4e594f; border-radius: 9px; color: #e2f5e7; background: #252d28; box-shadow: 0 10px 28px #0006; opacity: 0; pointer-events: none; font-size: .87rem; }
#notice.visible { opacity: 1; }
#notice.error { color: #ffd1d1; border-color: #6c454d; background: #39272a; }

@media (max-width: 1150px) {
  :root { --sidebar-width: 190px; }
  .sidebar { padding-inline: 13px; }
  .overview-grid { grid-template-columns: minmax(0, 1.65fr) minmax(240px, 1fr); }
  .chart-panel, .market-panel, .summary-panel, .business-panel, .settings-panel, .ledger-panel { padding-inline: 16px; }
}
@media (max-width: 900px) {
  :root { --sidebar-width: 155px; }
  .brand { gap: 7px; padding-inline: 3px; }
  .brand strong { font-size: 1.08rem; }
  .brand img { width: 33px; height: 33px; }
  .brand small { font-size: .67rem; }
  .build { display: block; }
  .build span + span { display: none; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { min-height: 110px; }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .market-panel, .summary-panel { min-height: 0; }
  .market-list { margin-bottom: 8px; }
}
@media (max-width: 670px), (max-width: 950px) and (max-height: 500px) {
  .shell, .sidebar { display: block; }
  .sidebar { position: static; height: auto; padding: 0; border: 0; }
  .sidebar .brand, .sidebar-footer, .nav-caption, .crumb { display: none; }
  .navigation { position: fixed; z-index: 2; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, 1fr); min-height: calc(var(--mobile-nav) + env(safe-area-inset-bottom)); padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); margin: 0; background: #151619; border-top: 1px solid var(--border); }
  .nav-link { flex-direction: column; justify-content: center; gap: 4px; padding: 2px 0; min-height: 51px; font-size: .73rem; }
  .topbar { position: sticky; z-index: 1; top: 0; min-height: calc(63px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(13px, env(safe-area-inset-right)) 0 max(13px, env(safe-area-inset-left)); gap: 7px; }
  .mobile-brand { display: flex; gap: 6px; min-height: 44px; }
  .mobile-brand strong { font-size: .94rem; letter-spacing: .07em; }
  .mobile-brand img { width: 29px; height: 29px; border-radius: 7px; }
  .turn-controls { gap: 6px; }
  .calendar { gap: 4px; min-height: 41px; padding: 0 6px; font-size: .76rem; }
  .calendar svg { width: 14px; }
  .turn-controls .button { gap: 3px; padding: 0 8px; font-size: .76rem; }
  .turn-controls .button svg { width: 14px; }
  main { padding: 22px max(13px, env(safe-area-inset-right)) calc(22px + var(--mobile-nav) + env(safe-area-inset-bottom)) max(13px, env(safe-area-inset-left)); }
  .page-heading { align-items: flex-start; margin-bottom: 17px; gap: 6px; }
  .page-heading p { font-size: .82rem; margin-top: 6px; word-break: keep-all; }
  .health { padding: 5px 7px; margin-top: 3px; font-size: .69rem; }
  .stat-card { padding: 10px 12px; }
  .stat-value { margin-top: 5px; font-size: 1.27rem; }
  .stat-top { font-size: .8rem; }
  .stat-caption { margin-top: 5px; font-size: .7rem; }
  .icon-tile { width: 34px; height: 34px; }
  .overview-grid, .overview-grid + .panel { margin-top: 12px; }
  .overview-grid { gap: 12px; }
  .panel-heading p { font-size: .77rem; }
  .chart-panel, .market-panel, .summary-panel, .business-panel, .settings-panel, .ledger-panel { padding: 15px 12px; }
  .segmented button { min-height: 44px; padding: 0 6px; }
  .chart-data summary { min-height: 44px; }
  .chart-summary { margin-top: 12px; }
  #growth-chart { height: 162px; }
  #notice { bottom: calc(var(--mobile-nav) + env(safe-area-inset-bottom) + 8px); left: 13px; right: 13px; max-width: none; }
  .business-row { grid-template-columns: auto minmax(0, 1fr) auto; gap: 7px 9px; }
  .business-profit { grid-column: 2; grid-row: 2; text-align: left; }
  .business-row .button { grid-row: 1 / 3; grid-column: 3; }
}
@media (max-width: 365px) {
  .calendar svg { display: none; }
  .mobile-brand img { width: 25px; height: 25px; }
  .mobile-brand strong { font-size: .84rem; }
  .turn-controls .button svg { display: none; }
  .chart-panel .panel-heading { flex-wrap: wrap; }
}
@media (max-height: 480px) {
  .topbar { position: static; }
}
