/* Home Base — layout & components. Design tokens: deep-space HUD.
   --bg #020810 · panel rgba(4,18,31,.72) · cyan #38bdf8 · bright #a5f3fc · gold #f5b544 */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: #020810; }
html, body { height: 100%; }
body {
  margin: 0; color: #e8f4fc; background: #020810; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: #e8f4fc; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: .04em; }
.err { color: #fda4af; min-height: 1.2em; font-size: 14px; }
.hint { color: #9db8c9; font-size: 13px; line-height: 1.45; }
[hidden] { display: none !important; }

/* ---------- wallpaper ---------- */
#wp { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: #020810; }
#wp-img, #wp-video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  object-position: var(--wp-focal-x, 50%) var(--wp-focal-y, 50%);
  animation: wp-drift 46s ease-in-out infinite alternate;
}
/* EMBERS preset (the Dark Knight poster): ~30s Ken Burns + warm glow flicker */
#wp[data-atmo="embers"] #wp-img { animation-duration: 30s; }
#wp-glow {
  position: absolute; left: 0; right: 0; top: 0; height: 42%; pointer-events: none; display: none;
  background: radial-gradient(ellipse 90% 100% at 50% 0%, rgba(255, 122, 26, .30), rgba(255, 84, 0, .10) 55%, transparent 75%);
  mix-blend-mode: screen;
}
#wp[data-atmo="embers"] #wp-glow.on { display: block; animation: glow-flicker 3.8s ease-in-out infinite; }
@keyframes glow-flicker { 0%, 100% { opacity: .75; } 28% { opacity: 1; } 47% { opacity: .62; } 63% { opacity: .92; } 81% { opacity: .7; } }
/* blurred-edge extension (very wide screens + focal poster: never crop the subject) */
#wp-blurbg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(34px) brightness(.62); transform: scale(1.15); display: none; }
@media (min-width: 1200px) {
  #wp-img.focal-fit { object-fit: contain; }
  #wp-blurbg.on { display: block; }
}
#wp-living { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#wp-dim { position: absolute; inset: 0; background: #020810; opacity: .25; pointer-events: none; }
@keyframes wp-drift { from { transform: scale(1.02) translate(0, 0); } to { transform: scale(1.1) translate(-1.2%, 1.5%); } }

/* ---------- views ---------- */
.view { position: relative; z-index: 1; height: 100dvh; display: flex; flex-direction: column; }

/* login */
#login-view { align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; }
.login-core { position: relative; width: 118px; height: 118px; margin-bottom: 8px; }
.core-ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(125, 211, 252, .85); }
.core-ring.r1 { border-style: dashed; animation: spin 24s linear infinite; }
.core-ring.r2 { inset: 16px; border-color: rgba(165, 243, 252, .55); animation: spin 14s linear infinite reverse; }
.core-tri {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 40px; transform: translate(-50%, -54%);
  background: #e0f2fe; clip-path: polygon(50% 0, 100% 100%, 0 100%);
  filter: drop-shadow(0 0 14px rgba(125, 211, 252, .95));
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-title { font-size: 30px; letter-spacing: .34em; text-indent: .34em; }
.login-sub { color: #7dd3fc; letter-spacing: .3em; font-size: 11px; margin: 0 0 14px; }
#login-form { display: flex; flex-direction: column; gap: 10px; width: min(320px, 86vw); }
#login-form input, #login-form button {
  padding: 13px 14px; border-radius: 12px; border: 1px solid rgba(125, 211, 252, .35);
  background: rgba(4, 18, 31, .78); backdrop-filter: blur(8px); font-size: 16px;
}
#login-form button { background: rgba(14, 116, 164, .55); font-weight: 650; letter-spacing: .06em; }
.ver-stamp { color: #7d99ad; font-size: 12px; margin-top: 16px; }

/* status bar */
#statusbar {
  display: flex; align-items: baseline; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 20px 4px;
  font-variant-numeric: tabular-nums; text-shadow: 0 1px 8px rgba(0,0,0,.7);
}
#sb-clock { font-size: 17px; font-weight: 700; letter-spacing: .03em; }
#sb-date { color: #cfe8f7; font-size: 13px; }
#sb-net { margin-left: auto; color: #4ade80; font-size: 10px; }
#sb-net.off { color: #f87171; }

/* pages */
#pages-viewport { flex: 1; overflow: hidden; position: relative; }
#pages { display: flex; height: 100%; transition: transform .38s cubic-bezier(.22, .9, .3, 1); }
.page {
  min-width: 100%; height: 100%; overflow-y: auto; overflow-x: hidden;
  padding: 12px 14px 8px; scrollbar-width: none;
}
.page::-webkit-scrollbar { display: none; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px 8px; grid-auto-rows: 84px; max-width: 560px; margin: 0 auto; }

/* tiles */
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 0; min-width: 0; }
.tile .icon {
  width: 60px; height: 60px; border-radius: 15px; display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex: none; box-shadow: 0 4px 14px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255,255,255,.22);
}
.tile .icon svg { width: 32px; height: 32px; }
.tile .icon img { width: 100%; height: 100%; object-fit: cover; }
.tile .icon .mono { font-size: 22px; font-weight: 750; color: #fff; letter-spacing: .02em; }
.tile .tlabel {
  font-size: 11.5px; line-height: 1.15; color: #fff; text-align: center; max-width: 76px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 6px rgba(0,0,0,.85);
}
#dock .tile .tlabel { display: none; }
#dock .tile .icon { width: 62px; height: 62px; }

/* dock */
#dock {
  display: flex; justify-content: space-around; align-items: center; gap: 6px;
  margin: 4px 14px calc(10px + env(safe-area-inset-bottom));
  padding: 10px 12px; border-radius: 28px;
  background: rgba(10, 25, 40, .55); backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid rgba(125, 211, 252, .22); max-width: 560px; width: calc(100% - 28px); align-self: center;
  min-height: 82px;
}
#dock:empty { display: none; }

/* dots */
#dots { display: flex; justify-content: center; gap: 7px; padding: 7px 0 2px; }
#dots button { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, .35); padding: 0; }
#dots button.on { background: #fff; }

/* talk button */
#talk-btn {
  align-self: center; display: flex; align-items: center; gap: 10px;
  margin: 6px 0 2px; padding: 9px 20px 9px 12px; border-radius: 999px;
  background: rgba(4, 18, 31, .72); border: 1px solid rgba(125, 211, 252, .45);
  backdrop-filter: blur(12px); font-weight: 650; letter-spacing: .05em;
  box-shadow: 0 0 22px rgba(56, 189, 248, .25);
}
.talk-orb {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 50% 50%, #f0faff 0 22%, #7dd3fc 45%, rgba(56, 189, 248, .15) 72%);
  box-shadow: 0 0 14px rgba(125, 211, 252, .9); animation: orb-pulse 2.6s ease-in-out infinite;
}
@keyframes orb-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* edit mode */
#done-btn, #add-btn {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); z-index: 60;
  padding: 7px 16px; border-radius: 999px; background: rgba(4, 18, 31, .85);
  border: 1px solid rgba(245, 181, 68, .7); color: #fcd34d; font-weight: 650; backdrop-filter: blur(8px);
}
#done-btn { right: 14px; }
#add-btn { left: 14px; }
body.editing .grid .item, body.editing #dock .tile { animation: wiggle .26s ease-in-out infinite alternate; }
body.editing .item:nth-child(2n) { animation-delay: -.13s; }
@keyframes wiggle { from { transform: rotate(-1.4deg); } to { transform: rotate(1.4deg); } }
.badge {
  position: absolute; top: -7px; left: 2px; z-index: 5; width: 22px; height: 22px; border-radius: 50%;
  background: #e5e7eb; color: #111827; font-size: 15px; line-height: 1; display: none;
  align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
body.editing .badge { display: flex; }
.drag-ghost { position: fixed; z-index: 90; pointer-events: none; opacity: .92; filter: drop-shadow(0 10px 22px rgba(0,0,0,.6)); animation: none !important; }
.drop-hint { outline: 2px dashed rgba(245, 181, 68, .8); outline-offset: 3px; border-radius: 16px; }

/* widgets */
.widget {
  position: relative; border-radius: 22px; padding: 12px 14px; overflow: hidden; min-width: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.widget.wide { grid-column: span 4; grid-row: span 2; }
.widget.small { grid-column: span 2; grid-row: span 2; }
.w-head { display: flex; align-items: center; gap: 8px; }
.w-title { font-size: 11px; letter-spacing: .22em; color: #a5f3fc; font-weight: 700; }
.w-src { margin-top: auto; font-size: 10.5px; color: #8fb0c4; letter-spacing: .02em; }
.w-body { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 0; }
.gauge-wrap { position: relative; width: 104px; height: 104px; flex: none; }
.gauge-wrap svg { width: 104px; height: 104px; transform: rotate(-90deg); }
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge-num { font-size: 30px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; }
.gauge-band { font-size: 10.5px; letter-spacing: .14em; color: #7dd3fc; }
.w-stats { display: flex; flex-direction: column; gap: 5px; font-size: 13px; min-width: 0; }
.w-stats b { font-variant-numeric: tabular-nums; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; border: 1px solid rgba(125, 211, 252, .4); font-size: 11.5px; color: #bae6fd; }
.chip.warn { border-color: rgba(248, 113, 113, .6); color: #fecaca; }
.chip.gold { border-color: rgba(245, 181, 68, .6); color: #fde68a; }
.w-list { display: flex; flex-direction: column; gap: 7px; width: 100%; }
.w-task { display: flex; align-items: center; gap: 9px; font-size: 14px; text-align: left; width: 100%; padding: 2px 0; }
.w-task .ring-btn { width: 21px; height: 21px; border-radius: 50%; border: 2px solid rgba(165, 243, 252, .7); flex: none; }
.w-task .tt { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-task .od { color: #fca5a5; font-size: 11.5px; }
.w-add { display: flex; gap: 8px; margin-top: 2px; }
.w-add input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid rgba(125, 211, 252, .3); background: rgba(2, 8, 16, .55); font-size: 14px; }
.w-add button { padding: 8px 13px; border-radius: 10px; background: rgba(14, 116, 164, .6); font-weight: 650; }
.bars { display: flex; flex-direction: column; gap: 7px; width: 100%; }
.bar-row { display: grid; grid-template-columns: 86px 1fr 34px; align-items: center; gap: 8px; font-size: 12.5px; }
.bar-track { height: 8px; border-radius: 99px; background: rgba(125, 211, 252, .14); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #0369a1, #38bdf8, #a5f3fc); box-shadow: 0 0 8px rgba(56, 189, 248, .55); }
.spark { width: 100%; height: 44px; }
.big-num { font-size: 34px; font-weight: 750; font-variant-numeric: tabular-nums; }
.count-num { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.empty-note { color: #9db8c9; font-size: 13.5px; line-height: 1.5; }

/* sheets */
#scrim { position: fixed; inset: 0; background: rgba(1, 4, 8, .55); z-index: 70; backdrop-filter: blur(2px); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  max-height: 88dvh; overflow-y: auto; padding: 10px 20px calc(18px + env(safe-area-inset-bottom));
  background: rgba(4, 16, 28, .92); backdrop-filter: blur(20px) saturate(1.25);
  border: 1px solid rgba(125, 211, 252, .25); border-bottom: 0; border-radius: 24px 24px 0 0;
  animation: sheet-up .3s cubic-bezier(.22, .9, .3, 1);
}
@keyframes sheet-up { from { transform: translateY(36px); opacity: .4; } }
.sheet-grab { width: 40px; height: 5px; border-radius: 99px; background: rgba(255, 255, 255, .28); margin: 2px auto 10px; }
.sheet-head, .talk-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sheet-head h2, .talk-head h2 { font-size: 19px; flex: 1; }
.sheet-x { font-size: 16px; padding: 8px; color: #9db8c9; }
.sheet h3 { font-size: 12px; letter-spacing: .22em; color: #7dd3fc; margin: 20px 0 10px; }
.sheet label { display: block; font-size: 13.5px; color: #cfe8f7; margin: 10px 0; }
.sheet input[type="text"], .sheet input:not([type]), .sheet input[type="password"], .sheet select, .sheet textarea,
#tile-form input, #forge-box textarea {
  width: 100%; margin-top: 5px; padding: 11px 12px; border-radius: 11px;
  border: 1px solid rgba(125, 211, 252, .3); background: rgba(2, 8, 16, .6); font-size: 15px;
}
.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.form-inline { display: flex; gap: 8px; margin-top: 5px; }
.form-inline input { flex: 1; margin-top: 0 !important; }
.form-inline button, .file-btn {
  padding: 11px 14px; border-radius: 11px; background: rgba(14, 116, 164, .55); font-weight: 650; white-space: nowrap;
}
button.primary { padding: 12px 18px; border-radius: 12px; background: rgba(14, 116, 164, .65); font-weight: 700; letter-spacing: .03em; }
button.danger { padding: 12px 16px; border-radius: 12px; border: 1px solid rgba(248, 113, 113, .55); color: #fecaca; }
.switch-row { display: flex !important; justify-content: space-between; align-items: center; gap: 12px; }
.switch-row input { width: 22px; height: 22px; accent-color: #38bdf8; }
input[type="range"] { width: 100%; accent-color: #38bdf8; }
input[type="color"] { width: 52px; height: 38px; padding: 2px; border-radius: 10px; border: 1px solid rgba(125,211,252,.3); background: rgba(2,8,16,.6); }

/* icon picker */
.icon-modes { display: flex; gap: 8px; margin: 8px 0; }
.icon-modes button { padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(125, 211, 252, .35); }
.icon-modes button.on { background: rgba(14, 116, 164, .6); border-color: #7dd3fc; }
.glyph-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 6px 0; }
.glyph-grid button { aspect-ratio: 1; border-radius: 10px; border: 1px solid transparent; display: flex; align-items: center; justify-content: center; background: rgba(125, 211, 252, .08); }
.glyph-grid button.on { border-color: #7dd3fc; background: rgba(14, 116, 164, .5); }
.glyph-grid svg { width: 22px; height: 22px; }
.color-row { display: flex; gap: 7px; flex-wrap: wrap; margin: 8px 0; }
.color-row button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.color-row button.on { border-color: #fff; }
#tf-preview { width: 60px; height: 60px; border-radius: 15px; object-fit: cover; margin-top: 8px; }

/* talk */
.talk-core { position: relative; width: 54px; height: 54px; flex: none; }
.talk-core .core-ring.r2 { inset: 8px; }
.talk-core .core-tri { width: 20px; height: 18px; }
#talk-status { color: #9db8c9; font-size: 13px; margin: 2px 0 0; }
#talk-log { display: flex; flex-direction: column; gap: 8px; max-height: 30dvh; overflow-y: auto; margin: 8px 0; }
.msg { padding: 9px 12px; border-radius: 13px; font-size: 14.5px; line-height: 1.45; max-width: 92%; }
.msg.jarvis { background: rgba(14, 116, 164, .28); border: 1px solid rgba(125, 211, 252, .3); align-self: flex-start; }
.msg.you { background: rgba(255, 255, 255, .1); align-self: flex-end; }
.talk-heard { min-height: 1.3em; color: #a5f3fc; font-size: 14px; font-style: italic; }
.talk-actions { display: flex; gap: 8px; align-items: stretch; }
#talk-mic { padding: 11px 14px; border-radius: 12px; border: 1px solid rgba(125, 211, 252, .5); font-weight: 650; white-space: nowrap; }
#talk-mic.listening { background: rgba(190, 24, 43, .35); border-color: rgba(248, 113, 113, .8); }
#talk-form { display: flex; gap: 8px; flex: 1; }
#talk-form input { flex: 1; min-width: 0; padding: 11px 12px; border-radius: 12px; border: 1px solid rgba(125, 211, 252, .3); background: rgba(2, 8, 16, .6); font-size: 15px; }
#talk-form button { padding: 11px 15px; border-radius: 12px; background: rgba(14, 116, 164, .6); font-weight: 650; }
.talk-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.talk-chips button { padding: 8px 13px; border-radius: 999px; border: 1px solid rgba(125, 211, 252, .35); font-size: 13.5px; }

/* add / forge / detail / settings */
.add-choices { display: flex; flex-direction: column; gap: 10px; }
.big-choice { padding: 16px; border-radius: 14px; border: 1px solid rgba(125, 211, 252, .35); background: rgba(14, 116, 164, .18); font-size: 16px; font-weight: 650; text-align: left; }
.sig-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sig-table td, .sig-table th { padding: 8px 6px; border-bottom: 1px solid rgba(125, 211, 252, .14); text-align: left; }
.sig-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.wp-gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wp-gallery button { position: relative; border-radius: 13px; overflow: hidden; padding: 0; aspect-ratio: 9 / 14; border: 2px solid transparent; }
.wp-gallery button.on { border-color: #7dd3fc; }
.wp-gallery img, .wp-gallery video { width: 100%; height: 100%; object-fit: cover; display: block; }
.wp-gallery span { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 6px 5px; font-size: 11px; text-align: left; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.feed-status { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.feed-status .row { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid rgba(125, 211, 252, .12); padding: 6px 0; }

#install-hint {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 65;
  padding: 11px 14px; border-radius: 14px; background: rgba(4, 18, 31, .92); border: 1px solid rgba(125, 211, 252, .4);
  font-size: 13.5px; backdrop-filter: blur(10px);
}
#toast {
  position: fixed; left: 50%; bottom: calc(118px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  z-index: 95; max-width: 88vw; padding: 11px 16px; border-radius: 13px; background: rgba(4, 18, 31, .94);
  border: 1px solid rgba(125, 211, 252, .45); font-size: 14px; opacity: 0; pointer-events: none; transition: .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* tablet / desktop */
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(6, 1fr); max-width: 860px; }
  .widget.wide { grid-column: span 4; }
  .sheet { left: 50%; right: auto; width: 580px; transform: translateX(-50%); border-radius: 24px; bottom: 18px; border-bottom: 1px solid rgba(125, 211, 252, .25); animation: sheet-up-c .3s cubic-bezier(.22,.9,.3,1); }
  @keyframes sheet-up-c { from { transform: translateX(-50%) translateY(30px); opacity: .4; } }
  #dock { max-width: 480px; }
}
@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(7, 1fr); max-width: 1060px; }
}
@media (prefers-reduced-motion: reduce) {
  #wp-img, #wp-video, .talk-orb, .core-ring, body.editing .item { animation: none !important; }
}
