:root {
  font-family: "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  color: #172a2c;
  background: #ebe7dd;
  --deep: #103332;
  --ink: #173e3d;
  --gold: #aa762c;
  --paper: #fbf8f0;
  --line: #d9d2c5;
  --muted: #6b7879;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 12% 0%, #f9f1df 0, transparent 29%), #ebe7dd; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
.topbar { display: flex; align-items: center; gap: 15px; min-height: 84px; padding: 15px clamp(18px, 4vw, 54px); color: #fffdf6; background: var(--deep); border-bottom: 3px solid #b78335; }
.brand-mark { display: grid; place-items: center; width: 45px; height: 45px; border: 1px solid #d4ad68; border-radius: 50%; color: #efcd8c; font: 700 21px/1 Georgia, serif; }
.topbar h1 { margin: 2px 0 0; font: 700 24px/1.2 "Songti TC", "Noto Serif TC", serif; letter-spacing: .07em; }
.eyebrow { margin: 0; color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .19em; }
.topbar .eyebrow { color: #d9b571; }
.version { margin-left: auto; padding: 5px 9px; border: 1px solid #54716f; border-radius: 999px; color: #e8cb91; font-size: 11px; }
.page-shell { display: grid; gap: 16px; max-width: 1800px; margin: 0 auto; padding: 18px; }
.control-card, .workspace-card, .notes-card { border: 1px solid var(--line); border-radius: 19px; background: rgba(255,253,247,.96); box-shadow: 0 9px 30px rgba(41,46,41,.05); }
.control-card, .notes-card { padding: 22px; }
.control-heading, .workspace-toolbar, .notes-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
h2, h3 { margin: 3px 0 0; font-family: "Songti TC", "Noto Serif TC", serif; }
h2 { font-size: 22px; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: #bb8c3e; }
.status.ready i { background: #4d9c77; box-shadow: 0 0 0 4px rgba(77,156,119,.12); }
.control-grid { display: grid; grid-template-columns: minmax(260px, 2fr) repeat(4, minmax(130px, 1fr)) minmax(170px, 1.2fr) auto; gap: 9px; margin-top: 17px; align-items: end; }
label { display: grid; gap: 6px; color: #58696b; font-size: 11px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cfd1cc; border-radius: 10px; padding: 9px 11px; color: #1b2d30; background: white; outline: none; }
input, select { min-height: 42px; }
input:focus, select:focus, textarea:focus { border-color: #9d793d; box-shadow: 0 0 0 3px rgba(170,118,44,.12); }
.check-field { grid-template-columns: 18px 1fr; align-items: center; min-height: 42px; padding: 7px 10px; border: 1px solid #e2d3b4; border-radius: 10px; background: #f8f1e1; }
.check-field input { width: 17px; min-height: 17px; accent-color: var(--deep); }
.check-field span { display: grid; gap: 2px; color: var(--ink); }
.check-field small { color: #7c8583; font-size: 8px; font-weight: 400; }
.sync-button { min-height: 42px; border: 0; border-radius: 10px; padding: 9px 16px; color: white; background: var(--deep); font-weight: 700; white-space: nowrap; }
.context-summary { margin: 12px 0 0; padding-top: 11px; border-top: 1px solid #e7e1d6; color: var(--muted); font-size: 11px; }
.workspace-card { overflow: hidden; }
.workspace-toolbar { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.view-switch { display: flex; padding: 3px; border: 1px solid #d7d2c9; border-radius: 10px; background: #f4f1ea; }
.view-switch button { border: 0; border-radius: 7px; padding: 7px 11px; color: #647071; background: transparent; font-size: 11px; }
.view-switch button.active { color: white; background: var(--deep); }
.frame-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); }
.tool-frame { min-width: 0; background: #f8f5ed; }
.tool-frame + .tool-frame { border-left: 1px solid var(--line); }
.tool-frame-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 9px 13px; border-bottom: 1px solid var(--line); background: #f1eadc; }
.tool-frame-head > div { display: flex; align-items: center; gap: 8px; }
.tool-frame-head span { display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid #c8a66a; border-radius: 50%; color: #916322; font-size: 9px; font-weight: 800; }
.tool-frame-head h3 { margin: 0; font-size: 14px; }
.tool-frame-head a { color: #7a5a27; font-size: 10px; text-decoration: none; }
iframe { display: block; width: 100%; height: min(78vh, 980px); min-height: 680px; border: 0; background: var(--paper); }
body[data-view="astrology"] .frame-grid, body[data-view="bazi"] .frame-grid { grid-template-columns: 1fr; }
body[data-view="astrology"] .bazi-frame, body[data-view="bazi"] .astrology-frame { display: none; }
.mobile-app-nav { display: none; }
.notes-heading > span { color: #89908e; font-size: 10px; }
.topic-list { display: flex; flex-wrap: wrap; gap: 7px; margin: 15px 0; }
.topic-list label { display: flex; align-items: center; gap: 5px; padding: 7px 10px; border: 1px solid #d7c9aa; border-radius: 999px; color: #785a29; background: #fffaf0; }
.topic-list input { width: 14px; min-height: 14px; accent-color: var(--deep); }
.note-field textarea { resize: vertical; min-height: 150px; line-height: 1.7; }
.completion-field { display: inline-flex; align-items: center; gap: 9px; margin-top: 12px; padding: 9px 12px; border: 1px solid #d7c9aa; border-radius: 10px; color: #536260; background: #fffaf0; cursor: pointer; }
.completion-field input { width: 17px; min-height: 17px; accent-color: var(--deep); }
.completion-field span { display: flex; align-items: baseline; flex-wrap: wrap; gap: 7px; }
.completion-field b { font-size: 12px; }
.completion-field small { color: #89908e; font-size: 10px; }
.note-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.note-actions button { border: 1px solid #bfa778; border-radius: 9px; padding: 8px 12px; color: #755421; background: transparent; }
.note-actions button:first-child { border-color: var(--deep); color: white; background: var(--deep); }
#note-status { color: #4c846b; font-size: 11px; }
footer { padding: 4px 8px 18px; color: #7b8584; font-size: 10px; text-align: center; }

@media (max-width: 1350px) {
  .control-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .control-grid .wide { grid-column: span 2; }
}

@media (max-width: 900px) {
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .page-shell { padding: 10px; }
  .control-grid { grid-template-columns: 1fr 1fr; }
  .control-grid .wide { grid-column: 1 / -1; }
  .frame-grid { grid-template-columns: 1fr; }
  .tool-frame + .tool-frame { border-left: 0; border-top: 1px solid var(--line); }
  iframe { height: 760px; min-height: 620px; }
  .mobile-app-nav {
    position: fixed;
    z-index: 1000;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    padding: 7px;
    border: 1px solid rgba(183, 131, 53, 0.55);
    border-radius: 18px;
    background: rgba(16, 47, 46, 0.96);
    box-shadow: 0 12px 34px rgba(7, 30, 30, 0.28);
    backdrop-filter: blur(12px);
  }
  .mobile-app-nav button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 46px;
    border: 0;
    border-radius: 12px;
    color: #dce7e4;
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 800;
  }
  .mobile-app-nav button span {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    font-size: 11px;
  }
  .mobile-app-nav button.active { color: #173a38; background: #f4e3be; }
  .mobile-app-nav button.active span { border-color: rgba(23, 58, 56, 0.3); }
}

@media (max-width: 560px) {
  .topbar { min-height: 72px; padding: 12px 15px; }
  .topbar h1 { font-size: 19px; }
  .version { display: none; }
  .control-card, .notes-card { padding: 16px; }
  .control-heading, .workspace-toolbar, .notes-heading { align-items: stretch; flex-direction: column; }
  .control-grid { grid-template-columns: 1fr; }
  .control-grid .wide { grid-column: auto; }
  .view-switch { display: grid; grid-template-columns: repeat(3, 1fr); }
  .view-switch button { padding-inline: 5px; }
  .workspace-toolbar { padding: 15px; }
  iframe { height: 690px; min-height: 560px; }
  .tool-frame-head h3 { font-size: 12px; }
}

@media print {
  body { background: white; }
  .topbar, .control-card, .workspace-toolbar, .tool-frame-head, .note-actions, .mobile-app-nav, footer { display: none !important; }
  .workspace-card, .notes-card { border: 0; box-shadow: none; }
  iframe { height: 900px; }
}
