:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --bg: #0b0c0e;
  --surface: #14171a;
  --surface-2: #1c2024;
  --line: #30363b;
  --text: #f5f7f8;
  --muted: #9ca5ad;
  --green: #43d095;
  --green-dark: #163e30;
  --amber: #f4b942;
  --danger: #ff675f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; letter-spacing: 0; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; overflow-x: hidden; }
button, input { font: inherit; }
button { color: inherit; }
button, label.file-btn { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
img, video { display: block; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { min-height: 100dvh; }
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(64px + var(--safe-top));
  padding: var(--safe-top) max(20px, var(--safe-right)) 0 max(20px, var(--safe-left));
  border-bottom: 1px solid var(--line);
  background: rgba(11, 12, 14, .94);
  backdrop-filter: blur(18px);
}
.brand, .license-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px; border-radius: 8px; color: #08110d; background: var(--green); }
.brand-copy { display: grid; min-width: 0; }
.brand-copy strong { overflow: hidden; font-size: 15px; line-height: 20px; text-overflow: ellipsis; white-space: nowrap; }
.brand-copy small { color: var(--muted); font-size: 11px; line-height: 15px; }
.save-state { color: var(--muted); font-size: 12px; white-space: nowrap; }

.workspace { width: min(860px, 100%); margin: 0 auto; padding: 28px max(20px, var(--safe-right)) calc(44px + var(--safe-bottom)) max(20px, var(--safe-left)); }
.page-heading, .editor-topbar, .section-heading, .asset-row, .form-actions, .dialog-actions { display: flex; align-items: center; }
.page-heading { justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-heading h1, .editor-topbar h1 { margin: 2px 0 0; font-size: 26px; line-height: 32px; }
.eyebrow { margin: 0; color: var(--green); font-size: 11px; font-weight: 700; text-transform: uppercase; }

.primary-btn, .secondary-btn, .danger-btn, .text-btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
}
.primary-btn, .secondary-btn, .danger-btn { gap: 8px; padding: 0 16px; }
.primary-btn { color: #06120d; background: var(--green); }
.secondary-btn { color: var(--text); border: 1px solid var(--line); background: var(--surface-2); }
.danger-btn { color: #fff; background: #9d2f2b; }
.text-btn { min-height: 36px; padding: 0 8px; color: var(--muted); background: transparent; }
.icon-btn { width: 42px; min-width: 42px; padding: 0; border: 1px solid var(--line); background: var(--surface-2); }
.primary-btn:disabled, .secondary-btn:disabled, .danger-btn:disabled { cursor: wait; opacity: .55; }
.full-btn { width: 100%; }

.app-list { border-top: 1px solid var(--line); }
.app-row { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; align-items: center; gap: 14px; min-height: 90px; padding: 14px 2px; border-bottom: 1px solid var(--line); }
.app-row-icon, .icon-preview, .install-icon-wrap img { width: 62px; height: 62px; object-fit: cover; border-radius: 22%; background: #20252a; box-shadow: 0 1px 8px rgba(0,0,0,.32); }
.app-row-copy { min-width: 0; }
.app-row-copy strong { display: block; overflow-wrap: anywhere; font-size: 16px; line-height: 22px; }
.app-row-copy small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 18px; }
.app-row-actions { display: flex; gap: 8px; }
.app-row-actions .icon-btn { width: 38px; min-width: 38px; min-height: 38px; }
.empty-state { display: grid; justify-items: center; gap: 16px; padding: 72px 16px; color: var(--muted); text-align: center; }
.empty-icon { display: grid; place-items: center; width: 58px; height: 58px; border: 1px solid var(--line); border-radius: 8px; }
.empty-icon svg { width: 26px; height: 26px; }

.editor-topbar { gap: 14px; margin-bottom: 14px; }
.editor-form { border-top: 1px solid var(--line); }
.form-section { display: grid; grid-template-columns: minmax(170px, .38fr) minmax(0, 1fr); gap: 28px; padding: 24px 2px; border-bottom: 1px solid var(--line); }
.section-heading { align-self: start; gap: 11px; }
.section-heading h2 { margin: 0; font-size: 16px; line-height: 22px; }
.section-heading small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 16px; }
.section-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border-radius: 7px; color: var(--green); background: var(--green-dark); }
.section-icon svg { width: 18px; height: 18px; }
.field { display: grid; gap: 8px; min-width: 0; }
.field > span { color: #cdd3d8; font-size: 12px; font-weight: 700; }
.field input { width: 100%; min-width: 0; height: 46px; padding: 0 13px; border: 1px solid var(--line); border-radius: 7px; outline: 0; color: var(--text); background: var(--surface); }
.field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(67,208,149,.12); }
.field input.invalid { border-color: var(--danger); }
.field-hint { color: var(--muted); font-size: 11px; line-height: 16px; }
.field-error { color: #ff8b85; font-size: 12px; }
.asset-row { gap: 18px; }
.icon-preview { width: 78px; height: 78px; flex: 0 0 78px; }
.asset-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.media-picker { display: flex; align-items: center; gap: 10px; }
.upload-progress { display: grid; gap: 7px; margin-top: 14px; }
.upload-progress span { color: var(--muted); font-size: 12px; }
.upload-progress i { overflow: hidden; height: 5px; border-radius: 3px; background: #292f34; }
.upload-progress b { display: block; width: 0; height: 100%; background: var(--green); transition: width .16s ease; }
.form-actions { position: sticky; bottom: 0; z-index: 10; gap: 10px; padding: 14px 2px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--line); background: rgba(11,12,14,.96); backdrop-filter: blur(18px); }
.action-spacer { flex: 1; }

.license-view { display: grid; place-items: center; min-height: 100dvh; padding: max(24px, var(--safe-top)) max(18px, var(--safe-right)) max(24px, var(--safe-bottom)) max(18px, var(--safe-left)); }
.license-panel { width: min(420px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 24px 70px rgba(0,0,0,.34); }
.license-brand h1 { margin: 2px 0 0; font-size: 22px; }
.license-form { display: grid; gap: 13px; margin-top: 26px; }
.license-note { margin: 14px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

.player-view { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; width: 100vw; height: 100dvh; overflow: hidden; background: #000; }
.player-view video, .player-view img { position: absolute; inset: 0; width: 100vw; height: 100dvh; object-fit: cover; background: #000; }
.player-error { display: grid; place-items: center; width: 100%; height: 100%; padding: 24px; color: #d8dde1; text-align: center; }
body.player-mode { overflow: hidden; background: #000; }

dialog { max-width: calc(100vw - 32px); color: var(--text); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 30px 90px rgba(0,0,0,.62); }
dialog::backdrop { background: rgba(0,0,0,.74); backdrop-filter: blur(4px); }
.install-dialog { width: min(420px, calc(100vw - 32px)); padding: 24px; }
.install-dialog h2, .confirm-dialog h2 { margin: 18px 0 8px; font-size: 19px; }
.install-dialog ol { margin: 14px 0 24px; padding-left: 22px; color: #d2d7db; line-height: 2; }
.install-icon-wrap { display: flex; align-items: center; gap: 14px; min-width: 0; }
.install-icon-wrap img { width: 60px; height: 60px; flex: 0 0 60px; }
.install-icon-wrap strong { overflow-wrap: anywhere; font-size: 17px; }
.dialog-actions { justify-content: flex-end; gap: 10px; }
.confirm-dialog { width: min(390px, calc(100vw - 32px)); padding: 22px; }
.confirm-dialog h2 { margin-top: 0; }
.confirm-dialog p { color: var(--muted); line-height: 1.6; }
.toast { position: fixed; left: 50%; bottom: calc(26px + var(--safe-bottom)); z-index: 200; max-width: calc(100vw - 32px); padding: 10px 14px; border-radius: 7px; color: #fff; background: #252b30; box-shadow: 0 12px 32px rgba(0,0,0,.4); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .app-bar { min-height: calc(58px + var(--safe-top)); padding-left: max(13px, var(--safe-left)); padding-right: max(13px, var(--safe-right)); }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .brand-copy strong { max-width: 60vw; font-size: 14px; }
  .workspace { padding: 20px max(14px, var(--safe-right)) calc(32px + var(--safe-bottom)) max(14px, var(--safe-left)); }
  .page-heading h1, .editor-topbar h1 { font-size: 22px; line-height: 28px; }
  .page-heading .primary-btn { width: 42px; min-width: 42px; padding: 0; }
  .page-heading .primary-btn span { display: none; }
  .app-row { grid-template-columns: 58px minmax(0,1fr) auto; gap: 11px; min-height: 84px; }
  .app-row-icon { width: 58px; height: 58px; }
  .app-row-actions { flex-direction: column; gap: 6px; }
  .app-row-actions .icon-btn { width: 36px; min-width: 36px; min-height: 36px; }
  .form-section { grid-template-columns: 1fr; gap: 16px; padding: 20px 0; }
  .section-heading { gap: 10px; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .action-spacer { display: none; }
  .form-actions .danger-btn { width: 42px; padding: 0; }
  .form-actions .danger-btn span { display: none; }
  .form-actions .secondary-btn { margin-left: auto; }
  .form-actions .primary-btn { flex: 1 1 100%; }
  .license-panel { padding: 24px 18px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-bar { min-height: calc(50px + var(--safe-top)); }
  .workspace { padding-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast, .upload-progress b { transition: none; }
}
