:root {
  color-scheme: light;
  font-family: "HarmonyOS Sans SC", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --ink: #17243d;
  --muted: #778397;
  --line: #dce4ed;
  --blue: #35587e;
  --blue-soft: #edf3f8;
  --danger: #b13838;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #fff; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #fff; color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .42; }
button:focus-visible, input:focus-visible { outline: 3px solid #84afe7; outline-offset: 3px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.modal-open { overflow: hidden; }
.dragging-category, .dragging-category * { cursor: grabbing !important; user-select: none !important; }

.app-shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; max-width: 680px; margin: 0 auto; padding: env(safe-area-inset-top) 22px env(safe-area-inset-bottom); }
.home-screen { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.home-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none; min-height: 65px; padding: 10px 2px 11px; }
.home-header h1 { margin: 0; font-size: clamp(26px, 6.8vw, 30px); line-height: 1.15; letter-spacing: .015em; font-weight: 750; }
.home-version { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.update-button { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 0; background: transparent; color: #697992; padding: 0; }
.home-main { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
.home-main::-webkit-scrollbar { display: none; }
.category-list { display: flex; flex-direction: column; gap: 8px; padding: 1px 1px 8px; }
.category-row { flex: none; height: var(--row-height, 126px); min-height: 90px; display: flex; flex-direction: column; justify-content: space-between; padding: 10px 10px 9px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.category-row.is-dragging { position: relative; z-index: 4; background: #fff; box-shadow: 0 12px 30px rgba(27, 46, 75, .19); border-color: #9daec2; transition: none; }
.category-row.drop-before { box-shadow: inset 0 3px 0 #6884a3; }
.category-row.drop-after { box-shadow: inset 0 -3px 0 #6884a3; }
.category-top { display: flex; align-items: center; gap: 6px; min-height: 30px; min-width: 0; }
.category-title { display: flex; align-items: center; gap: 5px; flex: 1; min-width: 0; min-height: 32px; padding: 0; border: 0; background: transparent; color: var(--ink); text-align: left; touch-action: none; }
.category-title strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(17px, 4.5vw, 20px); line-height: 1.25; font-weight: 700; letter-spacing: .005em; }
.category-grip { display: inline-flex; flex: none; align-items: center; color: #8491a5; }
.category-remaining { flex: none; white-space: nowrap; color: var(--blue); font-size: 14px; line-height: 1.2; }
.category-remaining strong { font-size: 22px; font-weight: 750; }
.category-remaining > span { color: #67758e; }
.category-remaining.is-unset { color: var(--muted); font-size: 14px; }
.category-settings { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 38px; height: 38px; margin-right: -4px; border: 0; background: transparent; color: #586c86; }
.category-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.category-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-width: 0; min-height: 44px; padding: 4px; border: 0; border-radius: 8px; background: var(--blue-soft); color: var(--ink); font-size: 15px; font-weight: 610; line-height: 1.2; }
.category-actions button svg { flex: none; color: var(--blue); }
.category-actions button:active, .category-title:active, .category-settings:active { background: #e0eaf3; }
.home-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: none; padding: 8px 1px 10px; background: #fff; }
.add-category, .archive-entry { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: 52px; border-radius: 10px; font-size: 16px; font-weight: 650; }
.add-category { border: 0; background: var(--blue-soft); color: var(--blue); }
.archive-entry { border: 0; background: var(--blue); color: #fff; }
.add-category:active { background: #dfe9f3; }
.archive-entry:active { background: #264662; }

.sub-header { display: flex; align-items: center; gap: 10px; padding: 25px 0 20px; border-bottom: 1px solid var(--line); }
.sub-header h1 { margin: 0; font-size: clamp(22px, 5.5vw, 27px); line-height: 1.3; font-weight: 690; }
.sub-header p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.back-button, .icon-button { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 42px; height: 42px; padding: 0; border: 0; background: transparent; color: var(--ink); }
.back-button { margin-left: -10px; }
.detail-main { flex: 1; padding: 22px 0 40px; }
.detail-footer { position: sticky; bottom: 0; z-index: 2; padding: 14px 0 max(14px, env(safe-area-inset-bottom)); margin-top: auto; background: #fff; border-top: 1px solid var(--line); }
.full-width { width: 100%; }
.primary-button, .secondary-button, .danger-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 50px; padding: 11px 16px; border-radius: 7px; font-size: 16px; font-weight: 650; line-height: 1.3; }
.primary-button { color: #fff; background: var(--blue); border: 1px solid var(--blue); }
.primary-button:active { background: #073a84; }
.secondary-button { color: var(--blue); background: #fff; border: 1px solid #a9bedb; }
.secondary-button:active { background: var(--blue-soft); }
.danger-button { color: #fff; background: var(--danger); border: 1px solid var(--danger); }
.text-button { border: 0; background: transparent; color: var(--muted); font-size: 14px; padding: 12px; }
.remove-category { display: block; margin: 20px auto 0; }
.batch-adjust { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 52px; margin: 0 0 18px; padding: 0 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--blue-soft); color: var(--blue); font-size: 15px; font-weight: 600; text-align: left; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 240px; color: #a3adbc; text-align: center; }
.empty-state p { margin: 14px 0 0; font-size: 15px; color: var(--muted); }
.photo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 13px; }
.photo-card { min-width: 0; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.photo-thumb { display: flex; align-items: center; justify-content: center; aspect-ratio: 3 / 4; overflow: hidden; background: #f3f5f8; }
.photo-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.photo-meta { display: flex; align-items: center; justify-content: space-between; gap: 4px; min-height: 36px; padding: 9px 9px 4px; color: var(--muted); font-size: 11px; line-height: 1.3; white-space: nowrap; }
.photo-meta > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.saved-label { color: #4b7a61; }
.pending-label { color: #ae6a19; }
.photo-controls { display: flex; align-items: center; justify-content: space-between; min-height: 38px; padding: 0 6px 5px; }
.photo-controls button { min-height: 32px; border: 0; background: transparent; color: var(--blue); font-size: 12px; text-align: left; }
.photo-controls .delete-photo { display: flex; align-items: center; justify-content: center; min-width: 32px; color: #8d98a8; margin-left: auto; }
.photo-grid + .secondary-button { margin-top: 22px; }
.empty-state + .secondary-button { margin-top: 4px; }
.archive-row { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 78px; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--line); background: #fff; color: var(--ink); text-align: left; }
.archive-row:active { background: var(--blue-soft); }
.archive-icon { color: #68758c; }
.archive-copy { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.archive-copy strong { font-size: 17px; line-height: 1.35; font-weight: 620; }
.archive-copy small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.archive-row > svg { color: #9ba5b7; }

#overlay-root:empty { display: none; }
.overlay-backdrop { position: fixed; inset: 0; z-index: 9; background: rgba(12, 24, 43, .45); }
.modal { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; max-width: 680px; max-height: min(86dvh, 740px); margin: 0 auto; padding: 20px 22px max(24px, env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; background: #fff; box-shadow: 0 -10px 35px rgba(12, 24, 43, .10); overflow-y: auto; }
.modal-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-top h2 { margin: 0; font-size: 21px; line-height: 1.35; font-weight: 700; }
.modal-top .icon-button { margin-right: -9px; color: #758196; }
.modal-body { margin-top: 14px; }
.modal-hint { margin: 0; color: #38455e; font-size: 15px; line-height: 1.65; }
.modal-hint strong { overflow-wrap: anywhere; }
.modal-note { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.modal-actions { display: grid; gap: 10px; margin-top: 22px; }
.source-options { display: grid; gap: 10px; margin-top: 20px; }
.source-options button { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 60px; padding: 11px 15px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--blue); text-align: left; font-size: 16px; font-weight: 590; }
.source-options button:active { background: var(--blue-soft); }
.input-label { display: block; margin-bottom: 8px; color: #3b4962; font-size: 14px; font-weight: 590; }
.text-input { display: block; width: 100%; height: 50px; padding: 0 13px; border: 1px solid #aebbd0; border-radius: 7px; background: #fff; color: var(--ink); font-size: 16px; }
.loading-line { height: 3px; margin-top: 22px; border-radius: 3px; background: linear-gradient(90deg, #dbe8f8, var(--blue), #dbe8f8); background-size: 200% 100%; animation: loading 1.5s linear infinite; }
@keyframes loading { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100vw - 34px); padding: 11px 17px; border-radius: 7px; background: #21304d; color: #fff; box-shadow: 0 8px 24px rgba(8, 20, 43, .2); font-size: 14px; line-height: 1.45; text-align: center; }
.toast.error { background: #8d3333; }
.fatal { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100dvh; padding: 28px; text-align: center; }
.fatal h1 { margin: 0; font-size: 24px; }
.fatal p { max-width: 460px; margin: 14px 0 24px; color: var(--muted); line-height: 1.6; }

@media (max-width: 370px) {
  .app-shell { padding-left: 17px; padding-right: 17px; }
  .home-header { min-height: 58px; padding-top: 7px; padding-bottom: 8px; }
  .category-row { padding: 7px 7px 6px; }
  .category-top { gap: 3px; }
  .category-title strong { font-size: 16px; }
  .category-grip svg { width: 14px; height: 14px; }
  .category-remaining { font-size: 12px; }
  .category-remaining strong { font-size: 18px; }
  .category-remaining.is-unset { font-size: 12px; }
  .category-settings { width: 34px; height: 34px; }
  .category-actions { gap: 4px; }
  .category-actions button { font-size: 14px; }
  .category-actions button svg { width: 19px; height: 19px; }
  .photo-grid { gap: 10px; }
}

@media (min-width: 681px) {
  body { background: #f5f7fa; }
  .app-shell { min-height: 100vh; background: #fff; box-shadow: 0 0 35px rgba(19, 31, 54, .08); }
}

@media (prefers-reduced-motion: reduce) {
  .loading-line { animation: none; }
}
