/* dashboard.css — house style by hand (phosphor cyan on deep navy, Inter).
   Tiles are absolutely positioned via transform from normalized rects (app.js reflect). */
:root {
  --bg: #040912;
  --accent: #5cd9ff;
  --amber: #f5b441;
  --panel: rgba(10, 20, 34, 0.82);
  --line: rgba(92, 217, 255, 0.16);
  --line-strong: rgba(92, 217, 255, 0.5);
  --ink: #d6ecf6;
  --muted: rgba(214, 236, 246, 0.55);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ---- board + tiles ---- */
.stage { flex: 1; position: relative; min-height: 0; }
.board { position: absolute; inset: 0; overflow: hidden; }
body.burn-in-drift .board { animation: burn-in-drift 180s ease-in-out infinite alternate; }
@keyframes burn-in-drift {
  0% { translate: -3px -2px; }
  33% { translate: 2px -3px; }
  66% { translate: 3px 2px; }
  100% { translate: -2px 3px; }
}
.home-mark {
  position: fixed; top: 18px; left: 20px; z-index: 45; display: flex; align-items: center; gap: 9px;
  color: var(--ink); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  transition: opacity 0.4s;
}
.home-mark-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px var(--accent); }
.surface-label { color: var(--muted); font-size: 10px; padding-left: 8px; border-left: 1px solid var(--line); }
.board-bg {
  position: absolute; inset: 0; z-index: 0; overflow: hidden;
  pointer-events: none; background: var(--bg);
}
.board-bg .embed {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
  pointer-events: none; background: var(--bg);
  transform: scale(1.03);
}
.board-bg::after {
  content: ""; position: absolute; inset: 0;
  background: rgba(4, 9, 18, var(--bg-dim, 0.35));
}

.tile {
  position: absolute; top: 0; left: 0;
  z-index: 10;
  container-type: size;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 16, 28, 0.42);
  backdrop-filter: blur(10px);
  overflow: hidden;
  transition: transform 0.18s ease, width 0.18s ease, height 0.18s ease, border-color 0.15s;
  will-change: transform;
}

/* ---- master digital ---- */
.w-master-digital {
  display: flex; flex-direction: column; justify-content: center; gap: 0.18em;
  width: 100%; height: 100%; padding: clamp(16px, 4vw, 44px);
}
.w-master-digital.align-left { align-items: flex-start; text-align: left; }
.w-master-digital.align-center { align-items: center; text-align: center; }
.w-master-digital.align-right { align-items: flex-end; text-align: right; }
.md-label, .md-date {
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em;
  font-size: clamp(11px, 1.4vw, 15px); font-weight: 600;
}
.md-time {
  color: var(--ink); font-weight: 700; line-height: 0.96; letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  font-size: clamp(36px, var(--md-scale, 14cqw), 154px);
  text-shadow: 0 0 28px rgba(92, 217, 255, 0.2);
}
.w-master-digital.size-compact { --md-scale: 10cqw; }
.w-master-digital.size-large { --md-scale: 17cqw; }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile.dragging { transition: none; z-index: 30; border-color: var(--line-strong); box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
body.editing .tile { border-color: var(--line-strong); cursor: move; }

.tile-body { position: absolute; inset: 0; }

/* ---- homepage tools ---- */
.tool-shell { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 9px; padding: 14px; overflow: auto; }
.tool-title { color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; font-size: 10px; font-weight: 700; }
.tool-row { display: flex; align-items: center; gap: 8px; }
.tool-input, .tool-select, .tool-textarea, .tool-button {
  font: inherit; font-size: 13px; color: var(--ink); background: rgba(4, 9, 18, 0.68);
  border: 1px solid var(--line); border-radius: 8px; min-height: 42px;
}
.tool-input, .tool-select, .tool-textarea { width: 100%; padding: 9px 10px; }
.tool-textarea { flex: 1; min-height: 72px; resize: none; line-height: 1.45; }
.tool-button { padding: 8px 12px; cursor: pointer; color: var(--accent); font-weight: 700; }
.tool-button:hover, .tool-input:focus, .tool-select:focus, .tool-textarea:focus { border-color: var(--accent); outline: none; }
.tool-output { padding: 9px 10px; min-height: 42px; border-radius: 8px; background: rgba(92,217,255,0.06); color: var(--ink); overflow-wrap: anywhere; }
.tool-hint { color: var(--muted); font-size: 11px; line-height: 1.4; }
.w-search { justify-content: center; }
.search-form { display: flex; gap: 8px; }
.search-form .tool-input { font-size: clamp(14px, 4cqw, 20px); min-height: 52px; }
.search-form .tool-button { min-width: 52px; }
.check-list { display: flex; flex-direction: column; gap: 5px; overflow: auto; }
.check-item { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.check-item span { flex: 1; overflow-wrap: anywhere; }
.check-item.done span { color: var(--muted); text-decoration: line-through; }
.check-delete { border: 0; background: transparent; color: var(--muted); cursor: pointer; min-width: 32px; min-height: 32px; }
.alt-preview { width: 100%; max-height: 42%; object-fit: contain; border-radius: 8px; background: rgba(0,0,0,.2); }

/* embeds: poster by default, iframe fades in when the pool makes it live */
.tile-body .poster, .tile-body .embed {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
}
.tile-body .poster { object-fit: cover; opacity: 1; transition: opacity 0.3s; }
.tile-body .embed { opacity: 0; transition: opacity 0.3s; background: var(--bg); }
.tile-body.is-live .poster { opacity: 0; }
.tile-body.is-live .embed { opacity: 1; }

/* drag scrim: inert when locked so embeds stay interactive; grabs pointer in edit mode */
.scrim { position: absolute; inset: 0; pointer-events: none; }
body.editing .scrim { pointer-events: auto; }
body.editing .tile-body .embed { pointer-events: none; }

/* resize handle + config gear: edit mode only */
.handle, .tile-edit { position: absolute; opacity: 0; pointer-events: none; transition: opacity 0.15s; }
body.editing .handle, body.editing .tile-edit { opacity: 1; pointer-events: auto; }
.handle {
  right: 0; bottom: 0; width: 22px; height: 22px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 45%, var(--accent) 45%, var(--accent) 60%, transparent 60%);
  /* enlarge the hit area to ~44px without growing the glyph */
  padding: 11px 0 0 11px; box-sizing: content-box;
}
.tile-edit {
  top: 6px; right: 6px; width: 44px; height: 44px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel); color: var(--accent); font-size: 15px; line-height: 1; cursor: pointer;
}
.tile-edit svg { width: 18px; height: 18px; }

/* ---- quicklaunch ---- */
.quicklaunch {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  text-decoration: none; color: var(--ink); padding: 10px; text-align: center;
}
.quicklaunch:hover { background: rgba(92, 217, 255, 0.06); }
.favicon {
  width: clamp(28px, 52cqw, 76px); height: clamp(28px, 52cqw, 76px);
  border-radius: 14px; object-fit: contain;
}
.favicon.glyph {
  display: flex; align-items: center; justify-content: center; color: var(--accent);
  background: rgba(92, 217, 255, 0.09); border: 1px solid var(--line);
  font-size: clamp(22px, 9vw, 40px); font-weight: 700;
}
.ql-label {
  font-size: clamp(10px, 16cqw, 15px); line-height: 1.15;
  color: var(--ink); overflow-wrap: normal; word-break: normal;
}
.ql-chip {
  position: absolute; inset: auto 0 0 0; flex-direction: row; gap: 8px;
  background: var(--panel); padding: 8px; justify-content: flex-start; border-top: 1px solid var(--line);
}
.ql-chip .favicon { width: 20px; height: 20px; }
.tile-body.preview-failed .embed { opacity: 0; }
.tile-body.preview-failed .ql-chip { inset: 0; flex-direction: column; }

/* ---- weather ---- */
.w-weather { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 10px; text-align: center; }
.w-glyph { font-size: clamp(26px, 5vw, 44px); color: var(--accent); }
.w-temp { font-size: clamp(22px, 5vw, 40px); font-weight: 700; }
.w-cond { font-size: 13px; color: var(--ink); }
.w-meta { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.w-loc { font-size: 11px; color: var(--muted); margin-top: 6px; }
.w-loading, .w-error { color: var(--muted); font-size: 12px; display: grid; place-items: center; position: absolute; inset: 0; }

/* ---- timezone ---- */
.w-tz { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px; }
.tz-time { font-size: clamp(22px, 5vw, 42px); font-weight: 700; color: var(--accent); letter-spacing: 0.04em; }
.tz-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; }

/* ---- APOD ---- */
.w-apod { position: absolute; inset: 0; }
.apod-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.apod-cap {
  position: absolute; inset: auto 0 0 0; padding: 8px 10px; font-size: 11px; color: var(--ink);
  text-decoration: none; background: linear-gradient(transparent, rgba(4,9,18,0.9));
}
.apod-cap:hover { color: var(--accent); }

/* ---- crypto ---- */
.w-crypto { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 12px; }
.cx-row { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.cx-id { flex: 1; color: var(--muted); text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; }
.cx-px { color: var(--ink); font-weight: 700; }
.cx-ch { font-size: 11px; min-width: 64px; text-align: right; color: var(--muted); }
.cx-ch.up { color: #7be3a4; }
.cx-ch.down { color: #ff8d8d; }

/* ---- toolbar ---- */
.toolbar {
  position: fixed; top: 12px; right: 12px; z-index: 50;
  display: flex; align-items: center; gap: 6px; padding: 6px;
  background: rgba(10, 20, 34, 0.62); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(6px);
}
body.is-idle .toolbar, body.is-idle .home-mark { opacity: 0; pointer-events: none; }
body[data-surface="screensaver"] .home-mark { opacity: 0; pointer-events: none; }
body[data-surface="screensaver"] .toolbar { opacity: 0.12; }
body[data-surface="screensaver"] .toolbar:hover, body[data-surface="screensaver"].editing .toolbar { opacity: 1; }
body[data-surface="display"] .home-mark { opacity: 0.45; }
.edit-tray { display: none; gap: 6px; }
body.editing .edit-tray { display: flex; }
.toolbar button {
  font: inherit; font-size: 13px; color: var(--ink);
  background: transparent; border: 1px solid var(--line); border-radius: 7px;
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.toolbar svg, .tile-edit svg {
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.toolbar svg { width: 19px; height: 19px; }
.toolbar button:hover { border-color: var(--line-strong); color: var(--accent); }
.toolbar button[aria-pressed="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }
body.editing .toolbar { background: var(--panel); border-color: var(--line-strong); }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(4, 9, 18, 0.7); }
.modal[hidden] { display: none; }
.modal-card {
  width: min(620px, 92vw); max-height: 86vh; overflow: auto;
  background: #07101c; border: 1px solid var(--line-strong); border-radius: 14px; padding: 20px;
}
.modal-card h2 { margin: 0 0 14px; font-size: 16px; color: var(--accent); }
.modal-types { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.type-search {
  width: 100%; min-height: 44px; padding: 9px 11px; color: var(--ink); background: #0a1626;
  border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.type-library { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; max-height: 260px; overflow: auto; }
.modal-types button {
  font: inherit; font-size: 12px; color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; min-height: 54px; cursor: pointer; text-align: left;
}
.modal-types button strong, .modal-types button span { display: block; }
.modal-types button span { color: var(--muted); font-size: 10px; margin-top: 3px; line-height: 1.3; }
.modal-types button[aria-pressed="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field-bool { flex-direction: row; align-items: center; gap: 8px; }
.field input[type="text"], .field input[type="url"], .field input[type="number"], .field select, .field textarea {
  font: inherit; font-size: 13px; color: var(--ink); background: #0a1626;
  border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px; min-height: 44px;
}
.field textarea { min-height: 110px; resize: vertical; }
.field input[type="range"] { accent-color: var(--accent); min-height: 44px; }
.field input:focus, .field select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.ambient-library-link { margin: 2px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.ambient-library-link a { color: var(--accent); text-underline-offset: 3px; }
.ambient-library-link a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.modal-actions .spacer { flex: 1; }
.ghost-btn, .primary-btn {
  font: inherit; font-size: 13px; border-radius: 7px; padding: 9px 14px; min-height: 44px; cursor: pointer;
}
.ghost-btn { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.ghost-btn[data-modal="delete"] { color: #ff8d8d; border-color: rgba(255, 141, 141, 0.4); }
.primary-btn { color: var(--bg); background: var(--accent); border: 1px solid var(--accent); font-weight: 700; }
.ghost-btn:focus-visible, .primary-btn:focus-visible, .favorite-key:focus-visible, .layout-card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px;
}

/* ---- saved layout library ---- */
.layout-library { width: min(980px, 94vw); max-height: 92vh; }
.layout-library-head { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
.layout-library-head h2 { margin-bottom: 0; }
.eyebrow {
  margin: 0 0 5px; color: var(--amber); font-size: 10px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase;
}
.layout-count { margin: 1px 0 0; color: var(--muted); font-size: 12px; white-space: nowrap; }
.layout-intro { max-width: 720px; margin: 13px 0 18px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.layout-copy-form, .layout-rename-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 9px; }
.layout-copy-form { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: rgba(92, 217, 255, 0.035); }
.layout-copy-form .primary-btn, .layout-rename-form .ghost-btn { white-space: nowrap; }
.layout-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px;
  margin: 16px 0; max-height: 330px; overflow: auto; padding: 3px;
}
.layout-card {
  position: relative; min-width: 0; padding: 0; overflow: hidden; text-align: left; cursor: pointer;
  color: var(--ink); background: rgba(4, 9, 18, 0.72); border: 1px solid var(--line); border-radius: 10px;
}
.layout-card:hover { border-color: var(--line-strong); }
.layout-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(92, 217, 255, 0.12); }
.layout-preview {
  display: grid; place-items: center; position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden;
  background: radial-gradient(circle at 30% 15%, rgba(92, 217, 255, 0.13), transparent 42%), #040912;
  border-bottom: 1px solid var(--line);
}
.layout-preview-canvas { display: block; position: relative; max-width: 100%; max-height: 100%; overflow: hidden; background: #040912; }
.layout-preview-canvas img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.58; }
.layout-preview-canvas::after { content: ""; position: absolute; inset: 0; background: rgba(4, 9, 18, 0.34); }
.layout-silhouette {
  position: absolute; z-index: 1; min-width: 2px; min-height: 2px;
  border: 1px solid rgba(214, 236, 246, 0.68); border-radius: 3px;
  background: rgba(92, 217, 255, 0.2); box-shadow: 0 0 8px rgba(92, 217, 255, 0.16);
}
.layout-card-copy { display: block; padding: 10px 11px 11px; }
.layout-card-title { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 13px; font-weight: 700; }
.layout-card-title > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout-card-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.35; text-transform: capitalize; }
.layout-shortcut { margin-left: auto; color: var(--amber); }
.layout-shortcut kbd, .favorite-key kbd {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px;
  color: var(--amber); background: rgba(245, 180, 65, 0.08); border: 1px solid rgba(245, 180, 65, 0.35); border-radius: 5px;
  font: 700 11px/1 'Inter', sans-serif;
}
.layout-details {
  display: grid; grid-template-columns: minmax(150px, 0.8fr) minmax(260px, 1.3fr) auto; align-items: end; gap: 14px;
  padding: 14px; background: rgba(92, 217, 255, 0.045); border: 1px solid var(--line); border-radius: 10px;
}
.layout-details h3 { margin: 0; color: var(--ink); font-size: 15px; }
.layout-details-copy > p:last-child { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.layout-favorites { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.layout-favorites > span { flex-basis: 100%; color: var(--muted); font-size: 11px; }
.favorite-key {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 7px 9px;
  color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 7px; cursor: pointer;
}
.favorite-key > span { font: 500 11px/1 'Inter', sans-serif; }
.favorite-key[aria-pressed="true"] { color: var(--ink); border-color: rgba(245, 180, 65, 0.55); background: rgba(245, 180, 65, 0.07); }
.danger-btn { grid-column: 3; justify-self: end; color: #ff8d8d; border-color: rgba(255, 141, 141, 0.4); white-space: nowrap; }
.danger-btn:disabled { opacity: 0.42; cursor: not-allowed; }
.layout-privacy { max-width: 600px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

@media (prefers-reduced-motion: reduce) {
  .tile, .handle, .tile-edit, .tile-body .poster, .tile-body .embed, .layout-card { transition: none; }
  body.burn-in-drift .board { animation: none; }
}

.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;
}

@media (max-width: 600px) {
  .home-mark { top: 16px; left: 14px; }
  .type-library { grid-template-columns: 1fr; }
  .layout-library { width: min(96vw, 620px); padding: 16px; }
  .layout-grid { grid-template-columns: 1fr; max-height: none; overflow: visible; }
  .layout-copy-form, .layout-rename-form, .layout-details { grid-template-columns: 1fr; }
  .layout-copy-form .primary-btn, .layout-rename-form .ghost-btn, .danger-btn { width: 100%; }
  .danger-btn { grid-column: 1; justify-self: stretch; }
  .layout-library .modal-actions { align-items: flex-end; }
  .layout-privacy { max-width: 72%; }
  .toolbar { left: auto; right: 10px; max-width: calc(100vw - 20px); overflow-x: auto; }
  .toolbar button { flex: 0 0 44px; width: 44px; height: 44px; }
}
