/* Firego launcher: a home screen, not a web page. Icons first, chrome second. */
:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --glow-a: #dde5ff;
  --glow-b: #efe4ff;
  --ink: #1b2130;
  --muted: #868ea0;
  --faint: #a7aebd;
  --line: #e3e7ee;
  --surface: #ffffffc2;
  --surface-solid: #fff;
  --surface-hover: #ffffffa6;
  --seg: #e8ebf1;
  --seg-active: #fff;
  --accent: #4a64c6;
  --accent-ink: #fff;
  --chip: #e8ecf5;
  --chip-ink: #48609a;
  --danger: #c0505f;
  --warn: #b07a2e;
  --ring: #4a64c61f;
  --ring-line: #a8b7de;
  --shadow: 0 1px 2px #1b213008, 0 8px 24px #1b21300d;
  --glass: #ffffffa8;
  --glass-line: #ffffffd9;
  --icon: 64px;
  --glyph: 31px;
  --radius: 15px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
/* Soft ambient light behind the grid; fixed so it does not scroll away. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 10% -14%, var(--glow-a), transparent 62%),
    radial-gradient(760px 460px at 100% -8%, var(--glow-b), transparent 58%);
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button, a { -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
[hidden] { display: none !important; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Layout */
.shell { width: min(100%, 880px); min-height: 100svh; margin: auto; padding: 0 40px; display: flex; flex-direction: column; }
header { height: 88px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 24px; font-weight: 700; letter-spacing: -1px; }
.brand svg { width: 26px; height: 26px; color: #33466e; }
#edit { min-height: 36px; padding: 0 14px; border: 0; border-radius: 18px; background: none; color: var(--muted); font-size: 13px; transition: background .2s, color .2s; }
#edit:hover { background: var(--chip); color: var(--chip-ink); }
main { flex: 1; }

/* Search + segmented categories */
.controls { display: flex; align-items: center; gap: 14px; margin-bottom: 30px; }
.search-box {
  flex: 1; height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  transition: border-color .2s, box-shadow .2s;
}
.search-box svg { width: 18px; flex-shrink: 0; color: var(--faint); }
.search-box:focus-within { border-color: var(--ring-line); box-shadow: 0 0 0 4px var(--ring); }
input { border: 0; outline: 0; background: none; width: 100%; min-width: 0; font-size: 15px; }
input::placeholder { color: var(--faint); }
kbd { font: 500 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--faint); border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; }
nav[aria-label="应用分类"] { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--seg); }
nav[aria-label="应用分类"] button { min-height: 38px; padding: 0 16px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-size: 13px; transition: background .2s, color .2s, box-shadow .2s; }
nav[aria-label="应用分类"] button[aria-pressed=true] { background: var(--seg-active); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px #1b213017; }

/* App grid: icon + name, like a phone home screen */
.apps { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 20px 10px; margin-bottom: 40px; }
.app { position: relative; min-width: 0; }
.app a { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 4px 10px; border-radius: 20px; transition: background .2s; }
.app-icon {
  position: relative; flex-shrink: 0; width: var(--icon); height: var(--icon);
  display: grid; place-items: center; border-radius: var(--radius); color: #fff;
  background: linear-gradient(150deg, #b39cff, #7656e4);
  box-shadow: inset 0 1px 0 #ffffff40, 0 8px 18px -10px var(--tone-shadow, #6d4fd8aa);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease);
}
.app-icon::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(180deg, #ffffff2b, transparent 55%); pointer-events: none; }
.app-icon svg { position: relative; width: var(--glyph); height: var(--glyph); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tone-0 { --tone-shadow: #6d4fd8aa; background: linear-gradient(150deg, #b39cff, #7656e4); }
.tone-1 { --tone-shadow: #1f9a62aa; background: linear-gradient(150deg, #6ddc9f, #23a066); }
.tone-2 { --tone-shadow: #2f62d8aa; background: linear-gradient(150deg, #78b1ff, #3a6ee3); }
.tone-3 { --tone-shadow: #e07a2caa; background: linear-gradient(150deg, #ffc86e, #f08637); }
.tone-4 { --tone-shadow: #1594a6aa; background: linear-gradient(150deg, #5edbd3, #1c9bb0); }
.app-icon.has-img { background: #fff; box-shadow: inset 0 0 0 1px #1b21300f, 0 8px 18px -12px #1b213066; }
.app-icon img { position: relative; width: 72%; height: 72%; object-fit: contain; }
.app strong { max-width: 100%; font-size: 12.5px; font-weight: 500; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-url { display: none; max-width: 100%; margin-top: -6px; font-size: 10px; line-height: 1.3; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editing .app-url { display: block; }
@media (hover: hover) {
  .app a:hover { background: var(--surface-hover); }
  .app a:hover .app-icon { transform: translateY(-3px); box-shadow: inset 0 1px 0 #ffffff40, 0 14px 24px -12px var(--tone-shadow, #6d4fd8aa); }
}
.app a:active .app-icon { transform: scale(.92); transition-duration: .08s; }
.app.is-target a { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--ring-line); }

.empty { padding: 48px 10px; text-align: center; color: var(--muted); font-size: 14px; }
.empty p { margin: 0; }
.empty button { margin-top: 16px; }

footer { display: flex; justify-content: space-between; gap: 12px; padding: 18px 0 max(22px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--faint); font-size: 11px; }
body.has-dock main { padding-bottom: 60px; }

/* Dock: the four apps this device opens most, in a frosted tray. */
#dock {
  --icon: 54px; --glyph: 27px; --radius: 13px;
  position: fixed; z-index: 30; left: 50%; bottom: max(16px, calc(env(safe-area-inset-bottom) + 6px));
  display: flex; gap: 16px; padding: 11px 15px; border-radius: 28px;
  background: var(--glass); border: 1px solid var(--glass-line);
  box-shadow: 0 12px 40px #1b21301f, inset 0 1px 0 #ffffff80;
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8);
  transform: translateX(-50%);
  animation: dock-in .5s var(--ease) both;
}
body.has-dock #dock { bottom: max(62px, calc(env(safe-area-inset-bottom) + 52px)); }
#dock a { display: block; border-radius: var(--radius); }
#dock a:active .app-icon { transform: scale(.9); transition-duration: .08s; }
@media (hover: hover) { #dock a:hover .app-icon { transform: translateY(-4px); } }
body:has(#search:focus) #dock { display: none; }
@keyframes dock-in { from { opacity: 0; transform: translate(-50%, 18px); } }

/* Editing: icons jiggle, a sticky bar keeps Save in reach. */
#editbar {
  position: sticky; top: max(10px, env(safe-area-inset-top)); z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -6px 0 22px; padding: 9px 9px 9px 16px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(20px) saturate(1.6); backdrop-filter: blur(20px) saturate(1.6);
}
#editbar span { margin-right: auto; font-size: 12px; color: var(--muted); }
#edit-hint.dirty { color: var(--warn); font-weight: 500; }
#editbar button, .reorder-actions button, .empty button { min-height: 36px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--chip); color: var(--chip-ink); font-size: 13px; }
#save-edit { background: var(--accent) !important; color: var(--accent-ink) !important; font-weight: 600; }
#manage-passkeys { white-space: nowrap; }
.editing .app a { cursor: pointer; }
.editing .app, .editing .app a, .editing .app img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
@keyframes jiggle { 0%, 100% { transform: rotate(-1.3deg); } 50% { transform: rotate(1.3deg); } }
.editing #apps .app-icon { animation: jiggle .3s ease-in-out infinite; }
.editing #apps .app:nth-child(even) .app-icon { animation-duration: .34s; animation-delay: -.17s; }
.drag-handle {
  position: absolute; z-index: 2; top: 2px; left: calc(50% + var(--icon) / 2 - 18px);
  width: 28px; height: 28px; border: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-solid); color: var(--muted); box-shadow: 0 2px 8px #1b213026; cursor: grab; touch-action: pan-y;
}
.drag-handle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 3.5; stroke-linecap: round; }
.drag-handle:active { cursor: grabbing; }
.drag-source { opacity: .25; }
.drag-ghost { position: fixed; z-index: 10000; pointer-events: none; transform: scale(1.08); }
.drag-ghost a { background: var(--surface-solid); box-shadow: 0 18px 40px #1b213033; }
.drag-ghost .drag-handle, .drag-ghost .app-url { display: none; }
.dragging { -webkit-user-select: none; user-select: none; }
.add-tile { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 4px 10px; border: 0; border-radius: 20px; background: none; color: var(--muted); font-size: 12.5px; }
.add-tile svg {
  width: var(--icon); height: var(--icon); padding: calc((var(--icon) - 26px) / 2);
  border: 1.5px dashed #b6c0d4; border-radius: var(--radius); color: var(--accent);
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; transition: border-color .2s, background .2s;
}
.add-tile:hover:not(:disabled) svg { border-color: var(--accent); background: var(--surface); }

/* Toast */
#notice {
  position: fixed; z-index: 10001; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  width: max-content; max-width: calc(100% - 32px); padding: 11px 18px; border-radius: 14px;
  background: #1f2533eb; color: #fff; font-size: 13px; line-height: 1.5; box-shadow: 0 10px 30px #1b213033;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  transform: translateX(-50%); animation: toast-in .3s var(--ease);
}
body.has-dock #notice { bottom: calc(108px + env(safe-area-inset-bottom)); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* Dialogs: centered card on desktop, bottom sheet on phones. */
dialog {
  width: min(420px, calc(100% - 32px)); max-height: calc(100svh - 40px); overflow: auto; padding: 24px;
  border: 1px solid var(--line); border-radius: 22px; background: var(--surface-solid); color: var(--ink);
  box-shadow: 0 24px 80px #1b213033;
}
dialog[open] { animation: pop .22s var(--ease); }
dialog::backdrop { background: #10141c4d; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes sheet { from { transform: translateY(100%); } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-size: 18px; font-weight: 650; }
.dialog-head button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--seg); color: var(--muted); font-size: 19px; line-height: 1; }
dialog label { display: block; margin: 12px 0; font-size: 12px; color: var(--muted); }
dialog input, dialog select { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); color: var(--ink); font-size: 16px; }
dialog input:focus, dialog select:focus { outline: none; border-color: var(--ring-line); box-shadow: 0 0 0 4px var(--ring); }
.primary { width: 100%; min-height: 46px; margin-top: 6px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-size: 15px; font-weight: 600; }
.secondary { width: 100%; min-height: 44px; margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--chip); color: var(--chip-ink); font-size: 14px; }
.danger { width: 100%; min-height: 44px; margin-top: 8px; border: 0; border-radius: 12px; background: none; color: var(--danger); font-size: 14px; }
.danger:hover { background: #c0505f12; }
.form-error { margin: 12px 0; color: var(--danger); font-size: 12px; line-height: 1.6; }
.form-error:empty { display: none; }
.reorder-actions { display: flex; gap: 8px; margin: 16px 0; }
.reorder-actions button { flex: 1; padding: 0 6px; font-size: 12px; }
.passkey-hint { margin: 4px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.passkey-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); font-size: 13px; }
.passkey-row button { min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--danger); }
.passkey-empty { margin: 14px 0 20px; color: var(--muted); font-size: 13px; }

/* Responsive */
@media (min-width: 601px) and (max-width: 849px) {
  .apps { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  :root { --icon: 58px; --glyph: 28px; --radius: 14px; }
  .shell { padding: 0 18px; }
  header { height: 68px; }
  .brand { font-size: 22px; }
  .brand svg { width: 23px; height: 23px; }
  .controls { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 22px; }
  .search-box { flex: none; height: 44px; border-radius: 13px; }
  input { font-size: 16px; }
  kbd { display: none; }
  nav[aria-label="应用分类"] button { flex: 1; padding: 0 6px; min-height: 34px; }
  .apps { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 2px; margin-bottom: 28px; }
  .app a, .add-tile { gap: 8px; padding: 8px 0 6px; }
  .app strong, .add-tile { font-size: 12px; }
  #editbar { gap: 6px; padding: 8px; }
  #editbar span { flex-basis: 100%; padding: 2px 6px 4px; }
  #editbar button { flex: 1; padding: 0 6px; }
  #dock { --icon: 54px; gap: 18px; padding: 10px 16px; }
  dialog {
    width: 100%; max-width: 100%; max-height: calc(100svh - 24px); margin: auto 0 0;
    padding: 20px 20px max(24px, env(safe-area-inset-bottom));
    border-width: 1px 0 0; border-radius: 24px 24px 0 0;
  }
  dialog[open] { animation: sheet .34s var(--ease); }
  footer { font-size: 10px; }
}
@media (max-width: 360px) {
  :root { --icon: 50px; --glyph: 25px; --radius: 12px; }
  .shell { padding: 0 14px; }
  .app strong { font-size: 11px; }
  #dock { --icon: 48px; gap: 14px; }
}

/* Dark mode follows the system. Icon colours stay vivid, like real app icons. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0d12; --glow-a: #19223f; --glow-b: #251a3b;
    --ink: #e7eaf1; --muted: #8b93a4; --faint: #5f6778; --line: #222835;
    --surface: #161a23c2; --surface-solid: #161a22; --surface-hover: #ffffff0b;
    --seg: #191e28; --seg-active: #2a313f;
    --accent: #5f7be0; --chip: #1f2532; --chip-ink: #b2c2ec;
    --danger: #ef8f9b; --warn: #e0b070; --ring: #5f7be033; --ring-line: #4a5c8c;
    --shadow: 0 1px 2px #0006, 0 8px 24px #0004;
    --glass: #1b202bb8; --glass-line: #ffffff14;
  }
  .brand svg { color: #b8c6ea; }
  .app-icon { box-shadow: inset 0 1px 0 #ffffff30, 0 10px 20px -12px #000; }
  .app-icon.has-img { background: #f3f4f7; }
  .drag-handle { box-shadow: 0 2px 8px #0009; }
  .add-tile svg { border-color: #394255; }
  #dock { box-shadow: 0 14px 40px #0009, inset 0 1px 0 #ffffff12; }
  #notice { background: #2a3142eb; box-shadow: 0 10px 30px #0008; }
  dialog { box-shadow: 0 24px 80px #000a; }
  dialog::backdrop { background: #0009; }
}

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