:root {
  --fg: #f4f5fb;
  --fg-dim: rgba(244, 245, 251, 0.66);
  --card: rgba(18, 20, 34, 0.42);
  --card-brd: rgba(255, 255, 255, 0.12);
  --accent: #8ab4ff;
  --accent-ink: #0f1220;
  --radius: 18px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--fg);
  background: #0f1220;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

:root {
  --bg-blur: 0px;
  --bg-gray: 0;
  --bg-dim: 0.45;
}

#bg, #bg-media, #bg-overlay {
  position: fixed;
  inset: 0;
  z-index: -2;
}

#bg {
  background-size: cover;
  background-position: center;
  transition: background 1.2s ease;
  transform: scale(1.04);
  filter: blur(var(--bg-blur)) grayscale(var(--bg-gray));
}
#bg.has-image { background-size: cover; background-position: center; }

#bg-media {
  overflow: hidden;
  pointer-events: none;
  transform: scale(1.04);
  filter: blur(var(--bg-blur)) grayscale(var(--bg-gray));
}
#bg-media video,
#bg-media iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(100vw, 177.78vh);
  height: max(100vh, 56.25vw);
  transform: translate(-50%, -50%);
  border: 0;
  pointer-events: none;
}

#bg-overlay {
  z-index: -1;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.22)),
    rgba(0, 0, 0, var(--bg-dim));
}

.stage {
  max-width: 1080px;
  margin: 0 auto;
  padding: max(28px, 6vh) 20px 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 34px;
}

/* Header / clock */
.top { text-align: center; }

.clock {
  font-size: clamp(3.4rem, 12vw, 6.5rem);
  font-weight: 200;
  letter-spacing: 0.01em;
  line-height: 1;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.35);
  font-variant-numeric: tabular-nums;
}

.greet {
  margin-top: 10px;
  font-size: clamp(1.1rem, 3.4vw, 1.7rem);
  font-weight: 300;
}

.date {
  margin-top: 4px;
  color: var(--fg-dim);
  font-size: 0.95rem;
}

/* Quote */
.quote-wrap {
  max-width: 620px;
  text-align: center;
}

.quote-text {
  margin: 0;
  font-size: clamp(1.05rem, 2.6vw, 1.35rem);
  font-weight: 300;
  line-height: 1.5;
  font-style: italic;
}

.quote-meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.quote-author {
  color: var(--fg-dim);
  font-style: normal;
  font-size: 0.9rem;
}

/* Widgets grid */
.widgets {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.pill {
  font-size: 0.72rem;
  color: var(--fg-dim);
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Buttons */
.btn {
  font: inherit;
  font-size: 0.85rem;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-brd);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.18); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }

.icon-btn {
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-brd);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.18); }

.linkish {
  font: inherit;
  font-size: 0.8rem;
  color: var(--fg-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0 0;
  text-decoration: underline;
}

/* Pomodoro */
.pomo-phase {
  text-align: center;
  color: var(--fg-dim);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pomo-time {
  text-align: center;
  font-size: clamp(2.6rem, 9vw, 3.4rem);
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 14px;
}
.pomo-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.pomo-modes {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 14px;
  flex-wrap: wrap;
}
.chip {
  font: inherit;
  font-size: 0.75rem;
  color: var(--fg-dim);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
}
.chip.active {
  color: var(--fg);
  border-color: var(--card-brd);
  background: rgba(255, 255, 255, 0.14);
}

/* Tasks */
.task-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.task-form input {
  flex: 1;
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-brd);
  border-radius: 10px;
  padding: 9px 12px;
}
input::placeholder, textarea::placeholder { color: rgba(244, 245, 251, 0.4); }
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.task-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 8px;
}
.task-list li:hover { background: rgba(255, 255, 255, 0.05); }
.task-list input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}
.task-list .txt {
  flex: 1;
  font-size: 0.9rem;
  word-break: break-word;
}
.task-list li.done .txt {
  text-decoration: line-through;
  color: var(--fg-dim);
}
.task-list .del {
  opacity: 0;
  background: none;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
  transition: opacity 0.12s ease;
}
.task-list li:hover .del,
.task-list .del:focus-visible { opacity: 1; }
.empty { color: var(--fg-dim); font-size: 0.85rem; padding: 6px; }

/* Notes */
#notes {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-brd);
  border-radius: 10px;
  padding: 12px;
}

.bottom {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: flex;
  gap: 8px;
}

/* Settings drawer */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: flex-end;
}
.drawer[hidden] { display: none; }
.drawer-panel {
  width: min(420px, 100%);
  height: 100%;
  background: #14162a;
  border-left: 1px solid var(--card-brd);
  display: flex;
  flex-direction: column;
  animation: slidein 0.22s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--card-brd);
}
.drawer-head h2 { margin: 0; font-size: 1.05rem; font-weight: 500; }
.drawer-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.field { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.field > legend { padding: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-dim); margin-bottom: 4px; }
.field > span { font-size: 0.85rem; color: var(--fg-dim); }
.field input[type="text"], .field input[type="number"], .drawer textarea {
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-brd);
  border-radius: 9px;
  padding: 9px 11px;
  width: 100%;
}
.drawer textarea { resize: vertical; line-height: 1.5; }
.row { display: flex; align-items: center; gap: 9px; font-size: 0.9rem; }
.row input { accent-color: var(--accent); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid3 label { display: flex; flex-direction: column; gap: 5px; font-size: 0.8rem; color: var(--fg-dim); }
.hint { font-size: 0.78rem; color: var(--fg-dim); margin: 0; line-height: 1.5; }
.hint code { background: rgba(255,255,255,0.1); padding: 1px 5px; border-radius: 4px; }

.bg-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.bg-swatch {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  background-size: cover;
  background-position: center;
}
.bg-swatch.active { border-color: var(--accent); }
.bg-swatch.special {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  background: rgba(255, 255, 255, 0.08);
}

.bg-custom { display: flex; gap: 8px; flex-wrap: wrap; }
.filebtn {
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-brd);
  text-align: center;
}
.filebtn:hover { background: rgba(255, 255, 255, 0.18); }
.field-sub { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--fg-dim); }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input[type="text"] { flex: 1; min-width: 140px; }
.slider { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; color: var(--fg-dim); }
.slider > span { display: flex; justify-content: space-between; }
.slider b { color: var(--fg); font-weight: 500; }
.slider input[type="range"] { width: 100%; accent-color: var(--accent); }

.danger-row { margin-top: 4px; }

@media (max-width: 560px) {
  .stage { gap: 26px; padding-top: 24px; }
  .pomo-controls .btn { flex: 1; }
}

/* ---- Layout edit mode -------------------------------------- */
body.lay-custom .stage {
  display: block;
  min-height: 100dvh;
  max-width: none;
  padding: 0;
}
body.lay-custom .widgets { display: block; }
body.lay-custom [data-drag] {
  position: fixed;
  margin: 0;
  z-index: 6;
  transform-origin: top left;
  width: min(360px, 90vw);
}
body.lay-custom #greeting { width: auto; }

body.editing { user-select: none; -webkit-user-select: none; }
body.editing [data-drag] {
  outline: 1px dashed rgba(255, 255, 255, 0.35);
  outline-offset: 6px;
  cursor: grab;
}
body.editing [data-drag]:hover { outline-color: var(--accent); }
body.dragging, body.dragging * { cursor: grabbing !important; }

.lay-tools {
  position: absolute;
  top: -34px;
  left: 0;
  display: flex;
  gap: 4px;
  z-index: 30;
}
.lay-tools button {
  font: inherit;
  font-size: 0.95rem;
  line-height: 1;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  background: #14162a;
  border: 1px solid var(--card-brd);
  border-radius: 7px;
  cursor: pointer;
}
.lay-tools button:hover { background: #23263e; }
.lay-tools [data-act="move"] { cursor: move; touch-action: none; }

.edit-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 8px 10px 8px 14px;
  background: #14162a;
  border: 1px solid var(--card-brd);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
}
.edit-bar[hidden] { display: none; }
.edit-bar span { color: var(--fg-dim); }
@media (max-width: 620px) {
  .edit-bar span { display: none; }
}

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