:root {
  --ink: #202522;
  --muted: #66706a;
  --line: #d9dedb;
  --surface: #ffffff;
  --canvas: #f3f5f4;
  --green: #168352;
  --green-soft: #e7f5ed;
  --blue: #2269a8;
  --amber: #b36a09;
  --red: #bd3732;
  --red-soft: #fbeceb;
  --focus: #1473c4;
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; letter-spacing: 0; }
[hidden] { display: none !important; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--canvas); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(20,115,196,.25); outline-offset: 2px; }

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #e9eeeb;
}
.login-panel { width: min(100%, 400px); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 28px; box-shadow: 0 14px 36px rgba(32,37,34,.1); }
.setup-hint { margin: 0 0 4px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.setup-hint code { padding: 1px 4px; border-radius: 3px; background: #eef2f0; color: var(--ink); font: 11px Consolas, monospace; }
#setupFields label { margin-top: 14px; }
.login-note { margin: 14px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; background: var(--ink); color: white; border-radius: 6px; font-weight: 800; }
.brand-mark.small { width: 36px; height: 36px; font-size: 13px; }
.login-panel h1 { margin: 18px 0 24px; font-size: 22px; }
.login-panel label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 600; }
.login-panel input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid #aeb7b2; border-radius: 4px; background: white; }
.primary-command { width: 100%; height: 44px; margin-top: 16px; border: 0; border-radius: 4px; background: var(--green); color: white; font-weight: 700; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--red); font-size: 13px; }

.topbar { min-height: 64px; padding: 10px max(16px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; background: var(--ink); color: white; }
.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-lockup h1, .brand-lockup p { margin: 0; }
.brand-lockup h1 { font-size: 17px; line-height: 18px; }
.brand-lockup p { margin-top: 2px; color: #bdc7c1; font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 7px; }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); font-size: 20px; line-height: 1; }
.topbar .icon-button { border-color: #4e5752; background: #2b312d; color: white; }
.connection-state { height: 30px; display: inline-flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid #46504a; border-radius: 15px; color: #dbe2de; font-size: 12px; white-space: nowrap; }
.signal-dot, .status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #929b96; }
.connection-state.online .signal-dot { background: #48cf89; box-shadow: 0 0 0 3px rgba(72,207,137,.15); }
.connection-state.offline .signal-dot { background: #e06d67; }

.summary-band { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); background: var(--surface); }
.summary-band div { min-height: 74px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--line); }
.summary-band div:last-child { border-right: 0; }
.summary-band strong { font-size: 22px; line-height: 24px; }
.summary-band span { margin-top: 4px; color: var(--muted); font-size: 11px; }

.content-band { padding: 22px max(16px, calc((100vw - 1180px) / 2)); }
.profiles-band { padding-bottom: 80px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: 17px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.profile-heading { align-items: center; }
.search-box { width: min(280px, 44vw); height: 38px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--muted); }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; }
.profile-table-head, .profile-row { display: grid; grid-template-columns: minmax(150px, 1.05fr) minmax(180px, 1.2fr) minmax(160px, 1.2fr) minmax(340px, 2fr); gap: 12px; align-items: center; }
.profile-table-head { min-height: 34px; padding: 0 12px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.profile-list { border-top: 1px solid var(--line); }
.profile-row { min-height: 76px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
.profile-row:hover { background: #fbfcfb; }
.profile-identity { min-width: 0; padding: 0; text-align: left; border: 0; background: transparent; color: inherit; }
.profile-name { display: block; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.profile-character { display: block; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 12px; }
.profile-status { min-width: 0; display: grid; grid-template-columns: 10px 1fr; column-gap: 7px; align-items: center; }
.profile-status small { grid-column: 2; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.profile-status[data-status="in-game"] .status-dot { background: var(--green); }
.profile-status[data-status="login"] .status-dot, .profile-status[data-status="starting"] .status-dot, .profile-status[data-status="restarting"] .status-dot { background: var(--blue); }
.profile-status[data-status="stale"] .status-dot, .profile-status[data-status="unknown"] .status-dot { background: var(--amber); }
.profile-status[data-status="error"] .status-dot, .profile-status[data-status="stopping"] .status-dot { background: var(--red); }
.profile-game { min-width: 0; }
.profile-game strong, .profile-game span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-game strong { font-size: 13px; }
.profile-game span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.profile-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.compact-command { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); font-size: 12px; }
.action-start { border-color: #a5d4bc; color: #106b43; }
.action-stop { border-color: #e2b7b4; color: #a22925; }
.schedule-switch { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; color: var(--muted); font-size: 11px; cursor: pointer; }
.schedule-switch input { position: absolute; opacity: 0; pointer-events: none; }
.schedule-switch span { width: 30px; height: 18px; position: relative; border-radius: 9px; background: #b7bfba; transition: background .15s; }
.schedule-switch span::after { content: ""; width: 14px; height: 14px; position: absolute; left: 2px; top: 2px; border-radius: 50%; background: white; transition: transform .15s; }
.schedule-switch input:checked + span { background: var(--green); }
.schedule-switch input:checked + span::after { transform: translateX(12px); }
.schedule-switch input:disabled + span { opacity: .35; }
.empty-state { padding: 42px; text-align: center; color: var(--muted); background: var(--surface); }

.confirm-dialog { width: min(calc(100% - 28px), 430px); padding: 0; border: 0; border-radius: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.24); }
.confirm-dialog::backdrop { background: rgba(22,27,24,.5); }
.confirm-dialog form { padding: 22px; }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 18px; }
.confirm-dialog p { margin: 0; color: var(--muted); line-height: 1.6; }
.release-option { margin-top: 16px; display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; }
.release-option input { width: 17px; height: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.dialog-actions button { min-width: 80px; height: 38px; border: 1px solid var(--line); border-radius: 4px; background: white; }
.dialog-actions .danger-command { border-color: var(--red); background: var(--red); color: white; }

.status-drawer { width: min(860px, 96vw); height: 100vh; height: 100dvh; position: fixed; z-index: 20; right: 0; top: 0; display: flex; flex-direction: column; transform: translateX(105%); transition: transform .2s ease; background: var(--canvas); color: var(--ink); box-shadow: -14px 0 40px rgba(0,0,0,.2); }
.status-drawer.open { transform: translateX(0); }
.status-drawer .drawer-head { flex: 0 0 auto; border-bottom-color: var(--line); background: var(--surface); }
.status-drawer .drawer-head p { color: var(--muted); }
.status-drawer .drawer-head .icon-button { border-color: var(--line); background: var(--surface); color: var(--ink); }
.status-drawer.stale .drawer-head p { color: var(--amber); font-weight: 600; }
.status-tabs { flex: 0 0 auto; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; padding: 12px 20px 0; border-bottom: 1px solid var(--line); background: var(--surface); }
.status-tab { min-width: 0; min-height: 42px; padding: 8px 4px; border: 1px solid var(--line); border-bottom: 3px solid transparent; border-radius: 6px 6px 0 0; background: var(--canvas); color: var(--muted); font-size: 12px; }
.status-tab:hover { color: var(--ink); background: #edf1ef; }
.status-tab[aria-selected="true"] { border-bottom-color: var(--green); background: var(--green-soft); color: #106b43; font-weight: 700; }
.status-content { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 0 20px max(30px, env(safe-area-inset-bottom)); }
.status-empty { margin: 28px 0; padding: 22px; border: 1px dashed #b8c1bc; border-radius: 6px; color: var(--muted); text-align: center; line-height: 1.6; background: var(--surface); }
.status-empty.error { border-color: #e2b7b4; color: var(--red); }
.status-empty.compact { margin: 0; padding: 14px; }
.status-section { padding: 22px 0; border-bottom: 1px solid var(--line); }
.status-section:last-child { border-bottom: 0; }
.status-section-head { margin-bottom: 13px; display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.status-section-head h3 { margin: 0; font-size: 16px; }
.status-section-head span { color: var(--muted); font-size: 11px; text-align: right; }
.status-metrics { display: grid; gap: 1px; border: 1px solid var(--line); background: var(--line); }
.overview-metrics { grid-template-columns: repeat(5, minmax(90px, 1fr)); }
.detail-metrics { margin-top: 12px; grid-template-columns: repeat(5, minmax(80px, 1fr)); }
.status-metric { min-width: 0; min-height: 62px; padding: 10px 11px; display: flex; flex-direction: column; justify-content: center; background: var(--surface); }
.status-metric span { color: var(--muted); font-size: 11px; }
.status-metric strong { margin-top: 5px; overflow-wrap: anywhere; font-size: 15px; }
.status-metric small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.status-metric.wide { grid-column: span 2; }
.online-time-note { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.vital-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.vital { padding: 11px 12px; border: 1px solid var(--line); background: var(--surface); }
.vital-label { margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.vital-label span { color: var(--muted); }
.progress-track { width: 100%; height: 8px; overflow: hidden; background: #dde3df; }
.progress-value { display: block; height: 100%; background: var(--green); transition: width .2s ease; }
.vital.life .progress-value { background: var(--red); }
.vital.mana .progress-value { background: var(--blue); }
.current-action { padding: 13px 14px; border-left: 4px solid var(--blue); background: var(--surface); }
.current-action span, .current-action strong, .current-action small { display: block; }
.current-action span { color: var(--muted); font-size: 11px; }
.current-action strong { margin-top: 5px; line-height: 1.5; }
.current-action small { margin-top: 6px; color: var(--muted); }
.current-action.error { border-left-color: var(--red); }
.current-action.waiting { border-left-color: var(--amber); }
.current-action.farming { border-left-color: var(--green); }
.current-action.town { border-left-color: #6d5f99; }
.next-target { margin: 13px 0 8px; font-size: 13px; font-weight: 600; }
.quest-progress { height: 6px; margin-bottom: 12px; }
.milestone-list { border-top: 1px solid var(--line); }
.milestone { min-height: 38px; display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 7px; border-bottom: 1px solid var(--line); font-size: 12px; }
.milestone-mark { font-size: 15px; color: #8a938e; }
.milestone.done .milestone-mark { color: var(--green); }
.milestone.done > span:nth-child(2) { color: #58615c; }
.milestone small { color: var(--muted); }
.milestone.optional.pending { opacity: .7; }
.score-summary { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 1px; border: 1px solid var(--line); background: var(--line); }
.score-summary .total-score strong { color: var(--green); font-size: 20px; }
.mercenary-score { margin-top: 16px; }
.score-note { margin: 10px 0 14px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.equipment-list { display: grid; gap: 8px; }
.equipment-item { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); overflow: hidden; }
.equipment-item.switch-item { border-style: dashed; }
.equipment-empty { min-height: 44px; padding: 9px 13px; display: flex; align-items: center; justify-content: space-between; border: 1px dashed var(--line); border-radius: 6px; background: #f8faf9; color: var(--muted); font-size: 11px; }
.equipment-empty strong { color: #8c9590; font-weight: 500; }
.equipment-item summary { min-height: 58px; padding: 10px 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; list-style: none; }
.equipment-item summary::-webkit-details-marker { display: none; }
.equipment-item summary::before { content: "›"; flex: 0 0 auto; color: var(--muted); font-size: 20px; transition: transform .15s; }
.equipment-item[open] summary::before { transform: rotate(90deg); }
.equipment-identity { min-width: 0; flex: 1; }
.equipment-identity small, .equipment-identity strong { display: block; }
.equipment-identity small { margin-bottom: 3px; color: var(--muted); font-size: 10px; }
.equipment-identity strong { overflow-wrap: anywhere; font-size: 13px; }
.item-score { flex: 0 0 auto; color: var(--green); font-weight: 700; }
.item-meta { padding: 9px 13px; display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--line); background: #f7f9f8; }
.item-meta span { padding: 3px 6px; border: 1px solid #cdd4d0; border-radius: 3px; color: #555f59; font-size: 10px; }
.item-requirements, .item-category { margin: 0; padding: 9px 13px 0; color: var(--muted); font-size: 11px; }
.attribute-list { margin-top: 10px; border-top: 1px solid var(--line); }
.attribute-row { min-height: 35px; padding: 7px 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid #edf0ee; font-size: 12px; }
.attribute-row strong { flex: 0 0 auto; color: var(--green); font-size: 11px; }
.muted-line { padding: 12px 13px; color: var(--muted); font-size: 11px; }
.item-notice { margin: 9px 13px; padding: 8px 10px; border-left: 3px solid var(--amber); background: #fff8ea; font-size: 11px; line-height: 1.55; }
.item-notice.alert { border-left-color: var(--red); background: var(--red-soft); }
.item-description { max-height: 220px; margin: 10px 13px 13px; padding: 10px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--line); background: #202522; color: #eaf0ec; font: 11px/1.55 Consolas, monospace; }
.skill-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.skill-row { min-height: 82px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; border: 1px solid var(--line); background: var(--surface); }
.skill-row strong { overflow-wrap: anywhere; font-size: 12px; }
.skill-row .skill-level { color: var(--blue); font-size: 11px; font-weight: 700; }
.skill-row small { grid-column: 1 / -1; color: var(--muted); }
.skill-metric { grid-column: 1 / -1; padding-top: 5px; border-top: 1px dashed var(--line); color: #245f47; font-size: 11px; line-height: 1.5; }
.skill-metric.damage { color: #9a491b; font-weight: 600; }

.log-drawer { width: min(720px, 94vw); height: 100vh; height: 100dvh; position: fixed; z-index: 20; right: 0; top: 0; display: flex; flex-direction: column; transform: translateX(105%); transition: transform .2s ease; background: #171b19; color: #edf3ef; box-shadow: -14px 0 40px rgba(0,0,0,.2); }
.log-drawer.open { transform: translateX(0); }
.drawer-backdrop { position: fixed; z-index: 19; inset: 0; background: rgba(20,24,22,.42); }
.drawer-head { min-height: 70px; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #343b37; }
.drawer-head h2, .drawer-head p { margin: 0; }
.drawer-head h2 { font-size: 16px; }
.drawer-head p { margin-top: 4px; color: #9eaba4; font-size: 11px; }
.drawer-head .icon-button { border-color: #46504a; background: #222825; color: white; }
.log-files { overflow: auto; padding: 14px; }
.log-file { margin-bottom: 14px; border: 1px solid #343b37; border-radius: 6px; overflow: hidden; }
.log-file header { padding: 9px 11px; background: #222825; color: #b9c4be; font-size: 11px; }
.log-file pre { max-height: 390px; margin: 0; padding: 12px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #dbe5df; font: 11px/1.55 Consolas, monospace; }
.toast-region { position: fixed; z-index: 40; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.toast { width: min(360px, calc(100vw - 32px)); padding: 11px 13px; border-radius: 4px; background: var(--ink); color: white; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 13px; }
.toast.error { background: #8f2824; }

@media (max-width: 820px) {
  .connection-state span:last-child { display: none; }
  .connection-state { width: 30px; justify-content: center; padding: 0; }
  .content-band { padding: 18px 12px; }
  .profile-table-head { display: none; }
  .profile-list { border-top: 0; display: grid; gap: 8px; }
  .profile-row { grid-template-columns: minmax(0, 1fr) minmax(130px, auto); gap: 10px; min-height: 0; padding: 12px; border: 1px solid var(--line); border-radius: 6px; }
  .profile-status { justify-self: end; max-width: 180px; }
  .profile-status small { max-width: 150px; }
  .profile-game { grid-column: 1 / -1; padding-top: 8px; border-top: 1px solid #edf0ee; }
  .profile-actions { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; }
  .schedule-switch { margin-left: auto; }
  .status-content { padding-inline: 12px; }
  .status-tabs { padding-inline: 12px; }
  .overview-metrics { grid-template-columns: repeat(3, minmax(80px, 1fr)); }
  .detail-metrics { grid-template-columns: repeat(3, minmax(75px, 1fr)); }
}

@media (max-width: 480px) {
  .summary-band div { min-height: 64px; }
  .summary-band strong { font-size: 19px; }
  .profile-heading { align-items: flex-start; flex-direction: column; }
  .search-box { width: 100%; }
  .profile-row { grid-template-columns: 1fr; }
  .profile-status { justify-self: start; }
  .profile-game, .profile-actions { grid-column: 1; }
  .compact-command span { display: none; }
  .compact-command { width: 36px; justify-content: center; padding: 0; font-size: 15px; }
  .status-section-head { align-items: flex-start; flex-direction: column; gap: 4px; }
  .status-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); padding-top: 8px; padding-bottom: 6px; }
  .status-tab { min-height: 38px; border-radius: 4px; }
  .status-section-head span { text-align: left; }
  .overview-metrics, .detail-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-metric.wide { grid-column: span 2; }
  .vital-grid { grid-template-columns: 1fr; gap: 8px; }
  .score-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .score-summary .total-score { grid-column: span 2; }
  .skill-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
