:root {
  color-scheme: dark;
  --bg-color: #0b0b14;
  --bg-gradient-1: #12132a;
  --bg-gradient-2: #0b0b14;
  --text-color: #e8e8f0;
  --muted-text: #9a9aab;
  --panel-bg: rgba(255, 255, 255, 0.05);
  --panel-border: rgba(255, 255, 255, 0.08);
  --input-bg: rgba(0, 0, 0, 0.2);
  --select-bg: #1a1b2e;
  --popover-bg: rgba(20, 21, 38, 0.95);
  --accent-color: #7c8cff;
  --accent-color-2: #a78bfa;
  --accent-color-3: #f472b6;
  --accent-color-4: #34d399;
  --danger-color: #ff6b7c;
  --success-color: #4ade80;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-color: #eef0fb;
  --bg-gradient-1: #f5f6ff;
  --bg-gradient-2: #e3e6fb;
  --text-color: #1b1b2b;
  --muted-text: #5b5b70;
  --panel-bg: rgba(255, 255, 255, 0.6);
  --panel-border: rgba(30, 30, 60, 0.08);
  --input-bg: rgba(255, 255, 255, 0.7);
  --select-bg: #ffffff;
  --popover-bg: rgba(255, 255, 255, 0.96);
  --accent-color: #5b6cf0;
  --accent-color-2: #8b5cf6;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at 20% 10%, var(--bg-gradient-1), var(--bg-gradient-2) 60%);
  background-attachment: fixed;
  color: var(--text-color);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: background 0.4s ease, color 0.4s ease;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 20px 30px, rgba(255,255,255,0.6), transparent),
    radial-gradient(1.5px 1.5px at 120px 90px, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 200px 150px, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.5px 1.5px at 300px 50px, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 400px 200px, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.5px 1.5px at 60px 250px, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 500px 100px, rgba(255,255,255,0.3), transparent);
  background-repeat: repeat;
  background-size: 550px 350px;
  opacity: 0.6;
}

:root[data-theme="light"] .stars {
  opacity: 0.15;
}

.dashboard {
  position: relative;
  z-index: 1;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  gap: 1rem;
  flex-shrink: 0;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.brand {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--accent-color), var(--accent-color-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  font-size: 0.7rem;
  color: var(--muted-text);
  letter-spacing: 0.01em;
}

.topbar-actions {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.theme-toggle,
.icon-button {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-color);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.2s ease, transform 0.1s ease;
}

.theme-toggle {
  padding: 0.5rem 1rem;
}

.icon-button {
  width: 2.5rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.settings {
  position: relative;
  display: flex;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 15rem;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1rem;
  background: var(--popover-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 10;
}

.settings-panel[hidden] {
  display: none;
}

.settings-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--muted-text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.settings-title-spaced {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--panel-border);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.setting-row select {
  background: var(--select-bg);
  color: var(--text-color);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.setting-row input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent-color);
  cursor: pointer;
}

.dashboard {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 1.5rem 1.5rem;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.hero {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 0 0;
}

.search-form {
  width: 100%;
  max-width: 1080px;
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.search-input {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background-color: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  color: var(--text-color);
  font-size: 1rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.search-button {
  padding: 0.85rem 1.25rem;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent-color), var(--accent-color-2));
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.clock-block {
  text-align: center;
}

.clock {
  font-size: clamp(2rem, 6vw, 3.25rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.clock-suffix {
  margin-left: 0.4em;
  font-size: 0.4em;
  font-weight: 600;
  color: var(--muted-text);
}

.clock-suffix:empty {
  display: none;
}

.date {
  color: var(--muted-text);
  margin-top: 0.25rem;
}

.panel-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
  color: var(--muted-text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.links-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 0.85rem;
}

.link-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  width: 4.25rem;
  text-align: center;
  text-decoration: none;
  color: var(--text-color);
  font-size: 0.72rem;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

.link-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: white;
}

.link-tile:nth-of-type(4n+1) .link-icon { background: var(--accent-color); }
.link-tile:nth-of-type(4n+2) .link-icon { background: var(--accent-color-2); }
.link-tile:nth-of-type(4n+3) .link-icon { background: var(--accent-color-3); }
.link-tile:nth-of-type(4n+4) .link-icon { background: var(--accent-color-4); }

.link-label {
  word-break: break-word;
}

.link-delete {
  position: absolute;
  top: -4px;
  right: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger-color);
  color: white;
  font-size: 0.6rem;
  line-height: 16px;
  border: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.link-tile:hover .link-delete,
.link-delete:focus-visible {
  opacity: 1;
}

.add-link-icon {
  background: transparent !important;
  border: 1.5px dashed var(--panel-border);
  color: var(--muted-text);
  font-size: 1.3rem;
}

.add-link-tile:hover .add-link-icon {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
}

.widget {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  overflow: hidden;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  transition: background 0.4s ease, border-color 0.4s ease;
}

.widget.is-hidden {
  display: none;
}

.widget-header {
  flex-shrink: 0;
  padding: 1.1rem 1.25rem 0;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.widget-header:active {
  cursor: grabbing;
}

.widget-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
}

.widget-body-center {
  align-items: center;
  text-align: center;
}

.resize-handle {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--muted-text) 50%);
  opacity: 0.45;
  border-radius: 2px;
  touch-action: none;
}

.resize-handle:hover {
  opacity: 0.9;
}

.todo-form {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  flex-shrink: 0;
}

.todo-input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background-color: var(--input-bg);
  color: var(--text-color);
  font-size: 0.9rem;
}

.todo-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.small-button {
  flex-shrink: 0;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, var(--accent-color), var(--accent-color-2));
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.small-button-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-color);
  border: 1px solid var(--panel-border);
}

.todo-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 0.9rem;
}

.todo-item.completed .todo-text {
  text-decoration: line-through;
  color: var(--muted-text);
}

.todo-text {
  flex: 1;
  cursor: pointer;
  word-break: break-word;
}

.todo-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.todo-edit,
.todo-delete {
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.todo-edit {
  color: var(--muted-text);
}

.todo-edit:hover {
  color: var(--accent-color);
}

.todo-delete {
  color: var(--danger-color);
  font-size: 1rem;
}

.todo-edit-input {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--accent-color);
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 0.9rem;
}

.timer-display {
  font-size: 2.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.timer-custom {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.85rem;
  flex-shrink: 0;
}

.timer-minutes-input {
  width: 4.5rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 0.85rem;
  text-align: center;
}

.timer-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-shrink: 0;
}

.timer-message {
  margin-top: 0.75rem;
  color: var(--success-color);
  font-size: 0.9rem;
  min-height: 1.2em;
  flex-shrink: 0;
}

.notes-area {
  flex: 1;
  width: 100%;
  min-height: 60px;
  resize: none;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background-color: var(--input-bg);
  color: var(--text-color);
  font-family: inherit;
  font-size: 0.9rem;
}

.notes-area:focus {
  outline: none;
  border-color: var(--accent-color);
}

@media (min-width: 801px) {
  .canvas {
    position: fixed;
    inset: 0;
    width: auto;
    z-index: 2;
    pointer-events: none;
  }

  .canvas .widget {
    pointer-events: auto;
  }

  .topbar {
    pointer-events: none;
  }

  .topbar .brand-block,
  .topbar .topbar-actions {
    pointer-events: auto;
  }
}

@media (max-width: 800px) {
  html, body {
    height: auto;
    overflow: auto;
  }

  .canvas {
    position: static;
    min-height: 840px;
  }
}
