:root {
  color-scheme: light;
  --canvas: #f2f1ef;
  --surface: #ffffff;
  --ink: #241f1e;
  --muted: #746b68;
  --line: #dedad7;
  --accent: #c9503e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 320px; min-height: 100%; margin: 0; }
body { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; background: var(--canvas); color: var(--ink); letter-spacing: 0; }
a, button { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible { outline: 3px solid rgba(201, 80, 62, .24); outline-offset: 3px; }

.topbar { min-height: 70px; padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .94); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; background: #3b2927; color: #fff; font-weight: 850; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 9px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.icon-button, .home-link, .boss-button { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.icon-button { width: 38px; padding: 0; cursor: pointer; font-size: 18px; }
.icon-button svg, .boss-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.boss-button { padding: 0 11px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 750; }
.home-link { padding: 0 12px; display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 750; text-decoration: none; }

main { width: min(1060px, calc(100% - 48px)); margin: 0 auto; padding: 56px 0 70px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 850; }
h1 { margin: 0; font-size: 34px; line-height: 1.2; }
.intro-note { margin: 0 0 4px; color: var(--muted); font-size: 12px; }

.app-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.app-card { width: 100%; min-height: 180px; padding: 26px; display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; gap: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: inherit; font: inherit; text-align: left; text-decoration: none; box-shadow: 0 10px 28px rgba(45, 32, 29, .05); cursor: pointer; transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease; }
.app-card:first-child { grid-column: 1 / -1; }
.app-card:hover { transform: translateY(-2px); border-color: #bdb2ae; box-shadow: 0 15px 34px rgba(45, 32, 29, .09); }
.app-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(201, 80, 62, .12); }
.app-icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 7px; background: var(--accent); color: #fff; }
.app-icon svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.letter-icon { font-size: 20px; font-weight: 850; }
.app-copy { min-width: 0; }
.app-copy > span, .app-copy strong { display: block; }
.card-meta { margin-bottom: 5px; color: var(--accent); font-size: 10px; font-weight: 850; }
.app-copy strong { margin-bottom: 7px; font-size: 19px; }
.app-copy > span:last-child { color: var(--muted); font-size: 13px; line-height: 1.55; }
.launch { color: #8a7e7a; font-size: 22px; }
.hupu .app-icon { background: #d84737; }
.hupu .card-meta { color: #b6382b; }
.timer .app-icon { background: #356b83; }
.timer .card-meta { color: #356b83; }
.food .app-icon { background: #b25c32; }
.food .card-meta { color: #a14b24; }
.picker .app-icon { background: #72558c; }
.picker .card-meta { color: #72558c; }
.chance .app-icon { background: #39705c; }
.chance .card-meta { color: #39705c; }
.zhihu .app-icon { background: #1769aa; }
.zhihu .card-meta { color: #1769aa; }
.sspai .app-icon { background: #d83f35; }
.sspai .card-meta { color: #bc332b; }
.douban .app-icon { background: #328c56; }
.douban .card-meta { color: #287648; }
.kitchen .app-icon { background: #b87326; }
.kitchen .card-meta { color: #98601f; }

.tool-panel { margin-top: 24px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 14px 36px rgba(45, 32, 29, .08); }
.tool-header { min-height: 74px; padding: 15px 18px 15px 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.tool-header .card-meta { margin: 0 0 3px; }
.tool-header h2 { margin: 0; font-size: 19px; }
.tool-content { min-height: 330px; padding: 34px; }
.timer-display { min-height: 178px; display: grid; place-content: center; justify-items: center; }
.timer-display span, .timer-display small { color: var(--muted); font-size: 11px; }
.timer-display strong { min-width: 5ch; margin: 5px 0 2px; font-size: 68px; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.segment-control { width: min(620px, 100%); margin: 0 auto; padding: 4px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; border: 1px solid var(--line); border-radius: 7px; background: #f4f2f0; }
.segment-control button { min-height: 42px; padding: 6px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; font-weight: 750; }
.segment-control button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 5px rgba(45, 32, 29, .12); }
.tool-actions { margin-top: 20px; display: flex; justify-content: center; gap: 9px; }
.primary-tool-button, .secondary-tool-button, .chance-actions button { min-height: 42px; padding: 0 18px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 800; }
.primary-tool-button { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.secondary-tool-button, .chance-actions button { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.tool-label { display: block; width: min(620px, 100%); margin: 0 auto 8px; color: var(--muted); font-size: 11px; font-weight: 800; }
.tool-textarea { width: min(620px, 100%); min-height: 142px; margin: 0 auto; padding: 13px; display: block; resize: vertical; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); outline: none; font: 13px/1.6 inherit; }
.tool-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201, 80, 62, .12); }
.random-result { width: min(620px, 100%); min-height: 92px; margin: 16px auto 0; display: grid; place-content: center; justify-items: center; border: 1px solid var(--line); border-radius: 7px; background: #f7f6f4; text-align: center; }
.random-result small, .chance-result small, .chance-result span { color: var(--muted); font-size: 11px; }
.random-result strong { max-width: 100%; padding: 4px 18px 0; overflow-wrap: anywhere; font-size: 24px; }
.chance-result { min-height: 220px; display: grid; place-content: center; justify-items: center; }
.chance-result strong { min-width: 3ch; margin: 7px 0; font-size: 72px; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.chance-actions { display: flex; justify-content: center; gap: 9px; }
.chance-actions button:hover, .secondary-tool-button:hover { border-color: #bdb2ae; background: #f8f6f5; }

.embedded-viewer { margin-top: 24px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); box-shadow: 0 14px 36px rgba(45, 32, 29, .08); }
.viewer-header { min-height: 74px; padding: 15px 18px 15px 22px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.viewer-header .card-meta { margin: 0 0 3px; }
.viewer-header h2 { margin: 0; font-size: 19px; }
.viewer-actions { display: flex; gap: 8px; }
.viewer-button { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; font: 700 20px/1 system-ui, sans-serif; text-decoration: none; }
.viewer-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.viewer-button:hover { border-color: #bdb2ae; background: #f8f6f5; }
.viewer-button:disabled { border-color: #e1ddda; background: #f7f5f3; color: #b8b0ac; cursor: not-allowed; }
.viewer-button.danger { color: #ad3025; }
.viewer-stage { position: relative; height: min(760px, 78vh); min-height: 520px; background: #e9e7e4; }
.viewer-stage iframe { position: relative; z-index: 1; width: 100%; height: 100%; display: block; border: 0; background: #fff; }
.viewer-loading { position: absolute; z-index: 2; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: #f7f6f4; color: var(--muted); font-size: 12px; }
.viewer-loading span { width: 30px; height: 30px; border: 2px solid #d6d0cc; border-top-color: var(--accent); border-radius: 50%; animation: viewer-spin .8s linear infinite; }
.viewer-loading p { margin: 0; }
.viewer-note { margin: 0; padding: 11px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.6; }
.embedded-viewer.pseudo-fullscreen { position: fixed; z-index: 80; inset: 0; width: 100%; height: 100%; margin: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; border: 0; border-radius: 0; background: #fff; }
.embedded-viewer.pseudo-fullscreen .viewer-stage { height: auto; min-height: 0; }
body.viewer-fullscreen { overflow: hidden; }
@keyframes viewer-spin { to { transform: rotate(360deg); } }

.settings-backdrop { position: fixed; z-index: 90; inset: 0; background: rgba(36, 31, 30, .42); backdrop-filter: blur(4px); }
.settings-dialog { position: fixed; z-index: 91; top: 50%; left: 50%; width: min(460px, calc(100% - 28px)); transform: translate(-50%, -50%); border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 24px 70px rgba(36, 31, 30, .24); }
.settings-header { min-height: 72px; padding: 14px 16px 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.settings-header h2 { margin: 0; font-size: 19px; }
.settings-header .card-meta { margin-bottom: 3px; }
.settings-body { padding: 22px 20px; display: grid; gap: 9px; }
.settings-intro { margin: 0 0 8px; padding: 11px 12px; border-left: 3px solid var(--accent); background: #fff8f6; color: #5f5552; font-size: 12px; line-height: 1.6; }
.field-label { color: var(--muted); font-size: 11px; font-weight: 800; }
.field-label:not(:first-child) { margin-top: 10px; }
.text-input, .shortcut-capture { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font: inherit; }
.text-input { padding: 0 13px; font-size: 13px; outline: none; }
.text-input:focus, .shortcut-capture:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201, 80, 62, .12); }
.shortcut-capture { padding: 0 13px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.shortcut-capture span { font-size: 14px; font-weight: 800; }
.shortcut-capture small { color: var(--muted); font-size: 10px; }
.shortcut-capture.capturing { border-color: var(--accent); background: #fff8f6; }
.settings-error { margin: 2px 0 0; color: #ad3025; font-size: 11px; }
.settings-footer { min-height: 66px; padding: 12px 20px; display: flex; align-items: center; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); }
.secondary-button, .save-button { min-height: 40px; padding: 0 15px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 750; }
.secondary-button { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.save-button { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.toast { position: fixed; z-index: 110; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); max-width: calc(100% - 32px); padding: 10px 14px; transform: translate(-50%, 16px); border-radius: 6px; background: #241f1e; color: #fff; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity 150ms ease, transform 150ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

footer { min-height: 74px; padding: 18px 24px calc(18px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: center; gap: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

@media (max-width: 720px) {
  .topbar { min-height: 62px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .brand small { display: none; }
  .boss-button { width: 38px; padding: 0; justify-content: center; }
  .boss-button span { display: none; }
  .home-link { width: 38px; padding: 0; justify-content: center; }
  .home-link span:last-child { display: none; }
  main { width: calc(100% - 28px); padding: 34px 0 48px; }
  .intro { align-items: flex-start; flex-direction: column; gap: 12px; }
  h1 { font-size: 28px; }
  .app-grid { grid-template-columns: 1fr; }
  .app-card:first-child { grid-column: auto; }
  .app-card { min-height: 142px; padding: 20px 17px; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 14px; }
  .app-icon { width: 46px; height: 46px; }
  .app-copy strong { font-size: 17px; }
  .app-copy > span:last-child { font-size: 12px; }
  .viewer-header { min-height: 66px; padding: 12px 12px 12px 16px; }
  .viewer-header > div:first-child { min-width: 0; }
  .viewer-header h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .viewer-actions { gap: 5px; }
  .viewer-button { width: 36px; height: 36px; }
  .tool-header { min-height: 66px; padding: 12px 12px 12px 16px; }
  .tool-content { min-height: 300px; padding: 26px 16px; }
  .timer-display { min-height: 150px; }
  .timer-display strong { font-size: 52px; }
  .segment-control { grid-template-columns: 1fr; }
  .segment-control button { min-height: 40px; }
  .chance-actions { display: grid; grid-template-columns: repeat(3, 1fr); }
  .chance-actions button { padding: 0 10px; }
  .viewer-stage { height: calc(100dvh - 184px); min-height: 520px; }
  .embedded-viewer.pseudo-fullscreen .viewer-stage { height: auto; min-height: 0; }
  .settings-footer { justify-content: stretch; }
  .settings-footer button { flex: 1; }
  footer { align-items: flex-start; flex-direction: column; gap: 4px; }
}

@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }
@media (prefers-reduced-motion: reduce) { .app-card { transition: none; } .viewer-loading span { animation: none; } }
