/* pwa-shell/styles.css —— 现代极简深色主题 */
:root {
  --bg: #0a0e17;
  --surface: #141a28;
  --surface-2: #1b2233;
  --border: #242d42;
  --text: #e7ebf4;
  --muted: #8a94ab;
  --accent: #5b7cfa;
  --accent-2: #8b5cf6;
  --danger: #f43f5e;
  --glass: rgba(20, 26, 40, .82);
  --overlay: rgba(5, 8, 14, .6);
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 22px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --tap: cubic-bezier(.2, .7, .3, 1);
}

/* 跟随系统浅色 */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1f7;
    --border: #e3e8f1;
    --text: #1a2233;
    --muted: #687287;
    --glass: rgba(255, 255, 255, .82);
    --overlay: rgba(15, 23, 42, .35);
    --shadow: 0 8px 30px rgba(31, 41, 70, .14);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 80% -10%, rgba(91, 124, 250, .14), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(139, 92, 246, .12), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

/* ---------- 面板 ---------- */
.panel {
  padding: 28px max(18px, env(safe-area-inset-left)) 40px;
  max-width: 760px;
  margin: 0 auto;
}
.panel__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.panel__title {
  font-size: 22px; font-weight: 650; letter-spacing: .2px; margin: 0;
  background: linear-gradient(120deg, var(--text), var(--muted));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.ios-hint {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 12px 14px; font-size: 13px; color: var(--muted); margin-bottom: 16px;
}

.panel__tools { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }

.search {
  width: 100%; padding: 12px 14px; margin-bottom: 16px; font-size: 14px;
  border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 124, 250, .22); }
.groups { display: flex; flex-direction: column; gap: 22px; }
.group__title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 12px 2px; letter-spacing: .3px; }

/* ---------- 站点网格（app 图标风格） ---------- */
.site-list {
  list-style: none; padding: 0; margin: 0 0 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(94px, 1fr)); gap: 18px 12px;
}
.site-card {
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  cursor: pointer; position: relative; padding: 4px 2px;
  transition: transform .18s var(--tap);
}
.site-card:active { transform: scale(.93); }
.site-card img, .site-card .ico {
  width: 64px; height: 64px; border-radius: 20px; object-fit: cover; display: block;
  background: linear-gradient(145deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: box-shadow .2s var(--tap), border-color .2s var(--tap);
}
.site-card:hover img, .site-card:hover .ico { border-color: var(--accent); box-shadow: 0 10px 28px rgba(91, 124, 250, .28); }
.site-card .ico {
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 600; color: var(--accent);
}
.site-card__name {
  font-size: 12.5px; line-height: 1.3; text-align: center; color: var(--muted);
  max-width: 86px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.site-card__edit {
  position: absolute; top: -4px; right: 2px;
  width: 22px; height: 22px; border-radius: 50%; padding: 0;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  font-size: 11px; cursor: pointer; opacity: 0; transform: scale(.8);
  transition: opacity .15s, transform .15s; display: flex; align-items: center; justify-content: center;
}
.site-card:hover .site-card__edit { opacity: 1; transform: scale(1); }
/* 触屏无 hover：编辑按钮常显，否则手机改不了站 */
@media (hover: none) { .site-card__edit { opacity: 1; transform: scale(1); } }

.empty-hint { color: var(--muted); font-size: 14px; text-align: center; padding: 48px 0; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid transparent; border-radius: var(--r-sm); padding: 11px 18px;
  font-size: 14px; font-weight: 550; cursor: pointer; color: var(--text);
  transition: transform .12s var(--tap), background .15s, border-color .15s, opacity .15s;
}
.btn:active { transform: scale(.96); }
.btn--primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 18px rgba(91, 124, 250, .35); }
.btn--primary:hover { opacity: .92; }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); border-color: var(--accent); }
.btn--sm { padding: 8px 14px; font-size: 13px; border-radius: 999px; }
#add-site-btn { width: 100%; padding: 13px; border-style: dashed; color: var(--muted); }
#add-site-btn:hover { color: var(--text); }

/* ---------- iframe 宿主 ---------- */
.host { position: fixed; inset: 0; background: var(--bg); }
.host__frame { border: 0; width: 100%; height: 100%; display: block; }

.host__loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 1; }
.spinner { width: 38px; height: 38px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.host__fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 32px; text-align: center; background: var(--bg); color: var(--muted);
}

/* ---------- 悬浮齿轮 + 菜单 ---------- */
.gear {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .08);
  background: linear-gradient(135deg, rgba(91, 124, 250, .9), rgba(139, 92, 246, .9));
  color: #fff; font-size: 21px; cursor: pointer; z-index: 3;
  box-shadow: 0 10px 28px rgba(91, 124, 250, .4); backdrop-filter: blur(8px);
  transition: transform .15s var(--tap);
}
.gear:active { transform: scale(.9) rotate(30deg); }
.gear-menu {
  position: fixed; right: max(16px, env(safe-area-inset-right));
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 58px); z-index: 3;
  display: flex; flex-direction: column; padding: 6px; gap: 2px; min-width: 168px;
  background: var(--glass); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow); backdrop-filter: blur(16px);
  animation: pop .14s var(--tap);
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }
.gear-menu button {
  border: none; background: transparent; color: var(--text); padding: 11px 14px; border-radius: var(--r-sm);
  font-size: 14px; text-align: left; cursor: pointer; transition: background .12s;
}
.gear-menu button:hover { background: var(--surface-2); }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center;
  padding: 18px; backdrop-filter: blur(6px); animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal__card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 24px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow); animation: rise .2s var(--tap);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal__card h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.modal__card label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
.modal__card input {
  padding: 11px 12px; border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.modal__card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 124, 250, .22); }
.modal__card input[type=color] { height: 42px; padding: 4px; cursor: pointer; }
.modal__card input[type=file] { color: var(--muted); }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
#form-delete { margin-right: auto; color: var(--danger); border-color: transparent; background: transparent; }
#form-delete:hover { background: rgba(244, 63, 94, .1); }

/* 键盘可访问：聚焦可见环 */
.btn:focus-visible, .site-card:focus-visible, .gear:focus-visible,
.gear-menu button:focus-visible, .modal__card input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Toast 轻提示（替代 alert） */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--glass); color: var(--text); border: 1px solid var(--border);
  padding: 12px 18px; border-radius: 999px; font-size: 14px; z-index: 9;
  box-shadow: var(--shadow); backdrop-filter: blur(14px); max-width: 86vw; text-align: center;
  animation: toast-in .2s var(--tap);
}
.toast--err { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

.install-modal {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  padding: 20px; background: rgba(15, 23, 42, .42); backdrop-filter: blur(12px);
}
.install-modal__card {
  width: min(420px, 100%); background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px; padding: 22px;
  box-shadow: var(--shadow);
}
.install-modal__card h2 { margin: 0 0 10px; font-size: 20px; }
.install-modal__card p { margin: 0 0 12px; color: var(--muted); line-height: 1.6; }
.install-modal__card .btn { width: 100%; margin-top: 4px; justify-content: center; }

[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
