:root {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: #e8ece8;
  background: #111512;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top, #1c261f 0%, #0e120f 55%, #090b09 100%); }
button { font: inherit; }

.app-shell { width: min(1560px, calc(100% - 28px)); margin: 0 auto; padding: 22px 0 28px; }
.topbar { display: flex; gap: 18px; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; padding: 0 4px; }
.eyebrow { margin: 0 0 5px; color: #8e9d91; letter-spacing: .16em; font-size: 12px; }
h1 { margin: 0; font-size: clamp(26px, 4vw, 44px); font-weight: 750; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ghost, .text-button, .panel-toggle { border: 1px solid #415047; color: #cbd5cd; background: #151b17; border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.ghost:hover, .text-button:hover, .panel-toggle:hover { background: #202a23; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(250px, 290px) minmax(520px, 1fr) minmax(280px, 330px);
  gap: 14px;
  align-items: stretch;
  min-height: calc(100vh - 125px);
}
.game-layout.history-collapsed { grid-template-columns: 54px minmax(520px, 1fr) minmax(280px, 330px); }
.game-layout.info-collapsed { grid-template-columns: minmax(250px, 290px) minmax(520px, 1fr) 54px; }
.game-layout.history-collapsed.info-collapsed { grid-template-columns: 54px minmax(520px, 1fr) 54px; }

.side-panel, .event-card {
  border: 1px solid #354139;
  background: rgba(15, 20, 17, .94);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0,0,0,.22);
}

.side-panel {
  height: calc(100vh - 138px);
  min-height: 620px;
  max-height: 920px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 14px 12px; border-bottom: 1px solid #2d3931; }
.panel-heading h2 { margin: 2px 0 0; font-size: 17px; }
.panel-kicker { color: #728178; font-size: 10px; letter-spacing: .15em; }
.panel-toggle { padding: 6px 9px; font-size: 12px; flex: 0 0 auto; }
.panel-body { min-height: 0; flex: 1; overflow: auto; padding: 12px 14px 16px; }
.side-panel.collapsed .panel-heading { height: 100%; padding: 10px 7px; flex-direction: column; justify-content: flex-start; border-bottom: 0; }
.side-panel.collapsed .panel-heading > div { display: none; }
.side-panel.collapsed .panel-toggle { writing-mode: vertical-rl; min-height: 78px; padding: 10px 8px; }
.side-panel.collapsed .panel-body { display: none; }

.story-column { min-width: 0; }
.event-card {
  height: calc(100vh - 138px);
  min-height: 620px;
  max-height: 920px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.event-story-scroll { min-height: 0; flex: 1; overflow-y: auto; padding: clamp(22px, 3vw, 34px); padding-bottom: 28px; }
.event-meta { display: flex; justify-content: space-between; color: #8fa096; font-size: 13px; margin-bottom: 18px; }
.event-card h2 { margin: 0 0 14px; font-size: clamp(28px, 4vw, 42px); }
.event-card p { margin: 0; color: #c6d0c8; line-height: 2; font-size: 17px; white-space: pre-wrap; }

.action-result-dock {
  flex: 0 0 auto;
  min-height: 116px;
  max-height: 168px;
  overflow-y: auto;
  padding: 11px clamp(18px, 3vw, 30px) 12px;
  border-top: 1px solid #354139;
  background: rgba(16, 23, 19, .98);
}
.action-result-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.action-result-heading span { color: #aebbb2; font-size: 13px; font-weight: 700; letter-spacing: .04em; }
.action-result-heading small { color: #718178; font-size: 11px; }
.action-result-content { display: grid; gap: 6px; }
.action-result-content.empty { color: #65736a; font-size: 12px; align-content: center; min-height: 62px; }
.action-result-title { color: #e4ebe6; font-size: 14px; font-weight: 700; }
.action-result-text { color: #aebbb2; font-size: 12px; line-height: 1.55; }
.action-result-changes { display: flex; flex-wrap: wrap; gap: 5px 7px; }
.action-result-chip { border: 1px solid #344139; background: #111713; border-radius: 999px; padding: 3px 7px; color: #9eaca3; font-size: 10px; }
.action-result-chip.good { border-color: #3e5b48; color: #b9cbbf; }
.action-result-chip.bad { border-color: #614444; color: #d1b0b0; }
.action-result-group-label { color: #718178; font-size: 10px; margin-right: 2px; align-self: center; }

.event-bottom-stack {
  flex: 0 0 auto;
  background: rgba(11, 15, 12, .98);
  border-top: 1px solid #354139;
  box-shadow: 0 -10px 28px rgba(0,0,0,.18);
}
.travel-dock {
  min-height: 94px;
  padding: 12px clamp(18px, 3vw, 30px) 10px;
  border-bottom: 1px solid #2d3931;
}
.travel-dock-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.travel-dock h3 { margin: 0; font-size: 13px; color: #aebbb2; letter-spacing: .05em; }
.travel-actions { display: grid; gap: 7px; }
.travel-actions-dock {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  min-height: 44px;
  align-content: start;
}
.travel-button {
  width: 100%;
  text-align: left;
  border: 1px solid #52645a;
  background: #1b2a20;
  color: #f0f4f1;
  border-radius: 9px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 650;
  min-height: 44px;
}
.travel-button:hover { background: #2b3a30; border-color: #7b9284; }
.travel-placeholder, .travel-empty { display: flex; align-items: center; min-height: 44px; color: #6f7d74; font-size: 12px; }

.choice-list {
  flex: 0 0 auto;
  display: grid;
  gap: 9px;
  max-height: 220px;
  overflow-y: auto;
  padding: 12px clamp(18px, 3vw, 30px) 18px;
  background: transparent;
}
.choice { width: 100%; text-align: left; border: 1px solid #52645a; background: #1b241e; color: #edf1ee; border-radius: 10px; padding: 14px 16px; cursor: pointer; transition: .15s ease; }
.choice:hover { transform: translateY(-1px); background: #263229; border-color: #71867a; }
.choice.danger { border-color: #785252; }

.side-section { padding: 2px 0 14px; }
.side-section + .side-section { border-top: 1px solid #2d3931; padding-top: 14px; }
.side-section h3 { margin: 0 0 10px; font-size: 13px; color: #aebbb2; letter-spacing: .05em; }

.info-body { overflow: hidden; display: flex; flex-direction: column; gap: 0; }
.status-section, .resource-section { flex: 0 0 auto; }
.inventory-section { flex: 1 1 auto; min-height: 140px; overflow-y: auto; padding-right: 4px; margin-right: -4px; }

.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { border: 1px solid #354139; background: rgba(18, 24, 20, .88); border-radius: 10px; padding: 10px; min-width: 0; }
.stat span, .resource-stat span { display: block; color: #8fa096; font-size: 11px; margin-bottom: 4px; }
.stat strong { display: block; font-size: 18px; overflow-wrap: anywhere; }
.stat.warning { border-color: #756a43; background: rgba(47, 43, 25, .72); }
.stat.danger { border-color: #7c4d4d; background: rgba(51, 28, 28, .74); }

.resource-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.resource-stat { border: 1px solid #3b493f; background: #121913; border-radius: 10px; padding: 11px; }
.resource-stat strong { font-size: 22px; }
.resource-stat.currency { grid-column: 1 / -1; }

.inventory-list { display: grid; gap: 5px; }
.inventory-row { width: 100%; border: 1px solid #344139; background: #111713; border-radius: 8px; padding: 7px 9px; display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; color: inherit; text-align: left; }
.inventory-row:hover { background: #18201b; border-color: #4b5d53; }
.inventory-row-name { font-size: 13px; color: #dce4de; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inventory-row-count { color: #9cac9f; font-size: 12px; flex: 0 0 auto; }
.empty-note { margin: 0; color: #6f7d74; font-size: 12px; }

.item-modal.hidden { display: none; }
.item-modal { position: fixed; inset: 0; z-index: 999; }
.item-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.62); backdrop-filter: blur(2px); }
.item-modal-panel { position: absolute; top: 50%; left: 50%; width: min(480px, calc(100vw - 28px)); transform: translate(-50%, -50%); border: 1px solid #354139; background: rgba(15, 20, 17, .99); border-radius: 14px; box-shadow: 0 22px 80px rgba(0,0,0,.48); overflow: hidden; }
.item-modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 15px 16px 13px; border-bottom: 1px solid #2d3931; }
.item-modal-head h3 { margin: 2px 0 0; font-size: 20px; }
.item-modal-body { padding: 15px 16px 17px; }
.item-modal-meta { color: #91a096; font-size: 12px; margin-bottom: 10px; }
.item-modal-desc { margin: 0 0 12px; color: #c3cec6; line-height: 1.75; font-size: 14px; }
.item-modal-price { min-height: 20px; color: #aab7ae; font-size: 12px; margin-bottom: 12px; }
.item-modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inventory-use, .inventory-sell { width: 100%; border: 1px solid #52645a; background: #1c281f; color: #e7eee9; border-radius: 8px; padding: 9px 10px; cursor: pointer; }
.inventory-use:hover, .inventory-sell:hover { background: #27362c; }
.inventory-sell { border-color: #685f45; background: #242116; }
.inventory-sell:hover { background: #322d1d; }
.inventory-use:disabled, .inventory-sell:disabled { cursor: not-allowed; opacity: .42; }

.log-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.text-button { border: 0; padding: 6px 7px; background: transparent; font-size: 12px; }
#history-log { padding-left: 20px; margin: 8px 0 0; }
#history-log li { padding: 0 0 18px 5px; color: #78887e; }
#history-log li > span { font-size: 11px; display: block; }
#history-log li > strong { display: block; color: #dce4de; margin: 3px 0; font-size: 13px; }
#history-log li > p { margin: 0; color: #9eaaa2; line-height: 1.55; font-size: 12px; }
.history-numbers { margin-top: 7px; padding: 7px 8px; border-left: 2px solid #3e5146; background: rgba(31, 41, 34, .55); border-radius: 0 7px 7px 0; font-size: 10px; line-height: 1.55; color: #8fa096; overflow-wrap: anywhere; }
.history-numbers b { display: inline-block; min-width: 32px; margin-right: 4px; color: #c2cec6; font-weight: 650; }

@media (max-width: 1120px) {
  .game-layout,
  .game-layout.history-collapsed,
  .game-layout.info-collapsed,
  .game-layout.history-collapsed.info-collapsed { grid-template-columns: minmax(0, 1fr) 300px; }
  .history-panel { grid-column: 1 / -1; height: auto; min-height: 0; max-height: 300px; order: 3; }
  .history-panel.collapsed { max-height: 48px; }
  .history-panel.collapsed .panel-heading { height: 48px; flex-direction: row; justify-content: space-between; padding: 8px 12px; }
  .history-panel.collapsed .panel-toggle { writing-mode: horizontal-tb; min-height: 0; }
  .story-column { grid-column: 1; }
  .info-panel { grid-column: 2; }
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 18px, 760px); padding-top: 14px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .game-layout,
  .game-layout.history-collapsed,
  .game-layout.info-collapsed,
  .game-layout.history-collapsed.info-collapsed { display: flex; flex-direction: column; }
  .story-column { order: 1; }
  .info-panel { order: 2; }
  .history-panel { order: 3; }
  .event-card { height: min(82vh, 820px); min-height: 610px; }
  .side-panel { height: auto; min-height: 0; max-height: 430px; }
  .side-panel.collapsed { max-height: 48px; }
  .side-panel.collapsed .panel-heading { height: 48px; flex-direction: row; justify-content: space-between; padding: 8px 12px; }
  .side-panel.collapsed .panel-toggle { writing-mode: horizontal-tb; min-height: 0; }
  .info-body { overflow-y: auto; display: block; }
  .inventory-section { overflow: visible; min-height: 0; margin-right: 0; padding-right: 0; }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .travel-actions-dock { grid-template-columns: 1fr; }
  .travel-dock { min-height: 92px; }
  .action-result-dock { min-height: 108px; max-height: 150px; }
  .choice-list { max-height: 210px; }
  .item-modal-actions { grid-template-columns: 1fr; }
}