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

/* 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);
}
.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: 40px; height: 40px; 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(440px, 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-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.modal-types button {
  font: inherit; font-size: 12px; color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 11px; min-height: 44px; cursor: pointer;
}
.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 select {
  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 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); }
.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; }

@media (prefers-reduced-motion: reduce) {
  .tile, .handle, .tile-edit, .tile-body .poster, .tile-body .embed { transition: 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) {
  .toolbar { left: auto; right: 10px; max-width: calc(100vw - 20px); overflow-x: auto; }
  .toolbar button { flex: 0 0 40px; width: 40px; height: 40px; }
}
