:root {
  --bg: #f6f2ea;
  --glow: rgb(255 196 120 / 0.45);
  --surface: #fffdf9;
  --surface-2: #efe9dd;
  --text: #1d1b17;
  --muted: #6f695e;
  --border: #e4ddcf;
  --accent: #e07b24;
  --accent-soft: rgb(224 123 36 / 0.12);
  --shadow: 0 1px 2px rgb(40 30 10 / 0.05), 0 8px 24px rgb(40 30 10 / 0.06);
  --shadow-lift: 0 2px 4px rgb(40 30 10 / 0.08), 0 20px 40px rgb(40 30 10 / 0.16);
  --radius: 20px;

  --day-from: #fffaf0;
  --day-to: #ffefd6;

  /* Ночные карточки тёмные в обеих темах — как виджет часов в macOS */
  --night-from: #222a3d;
  --night-to: #161b28;
  --night-text: #eef1f8;
  --night-muted: #9aa3b8;
  --night-border: #2d364b;

  --face-day: #ffffff;
  --face-day-ink: #111111;
  --face-night: #2b2c30;
  --face-night-ink: #ffffff;
  --second-hand: #f09a37;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121419;
    --glow: rgb(240 154 55 / 0.14);
    --surface: #1b1e25;
    --surface-2: #252932;
    --text: #edeae3;
    --muted: #9b968c;
    --border: #2a2e37;
    --accent: #f09a37;
    --accent-soft: rgb(240 154 55 / 0.14);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
    --shadow-lift: 0 2px 4px rgb(0 0 0 / 0.4), 0 20px 40px rgb(0 0 0 / 0.5);

    --day-from: #2b261d;
    --day-to: #241f17;
    --night-from: #1c2234;
    --night-to: #141826;
    --night-border: #262d42;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 85% -120px, var(--glow), transparent 70%),
    var(--bg);
  background-repeat: no-repeat;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--accent); }

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar, main, .footer {
  max-width: 1120px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

@media (min-width: 720px) {
  .topbar, main, .footer { padding-left: 32px; padding-right: 32px; }
}

/* ---------- Верхняя панель ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 20px;
  padding-bottom: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand:hover { color: inherit; }

.brand-mark, .empty-sun {
  fill: var(--accent);
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
}
.brand-mark { width: 26px; height: 26px; }

/* На узком экране: логотип и язык в первой строке, переключатели вида — во второй. */
.controls { order: 2; width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
.lang-switch { order: 1; margin-left: auto; }
.controls .segmented { flex: 1 1 auto; }
.controls .segmented button { flex: 1; }

@media (min-width: 820px) {
  .controls .segmented { flex: none; }
  .controls { order: 1; width: auto; margin-left: auto; }
  .lang-switch { order: 2; margin-left: 0; }
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 12px;
}
.segmented button {
  padding: 6px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}

/* ---------- Первый экран ---------- */

.hero { padding: 40px 0 28px; max-width: 760px; }

@media (min-width: 720px) {
  .hero { padding-top: 72px; }
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 1.05;
  font-weight: 750;
  letter-spacing: -0.035em;
}

.lead {
  margin: 16px 0 28px;
  max-width: 600px;
  font-size: 1.125rem;
  color: var(--muted);
}

.search { position: relative; }

.search-icon {
  position: absolute;
  top: 50%;
  left: 18px;
  width: 20px;
  height: 20px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 16px 18px 16px 50px;
  font: inherit;
  font-size: 1.05rem;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search-input::placeholder { color: var(--muted); opacity: 0.8; }
#search-input:focus { border-color: var(--accent); box-shadow: var(--shadow), 0 0 0 4px var(--accent-soft); }

.results {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  margin: 6px 0 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lift);
  max-height: 340px;
  overflow-y: auto;
}
.results li {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.results li[aria-selected="true"], .results li:hover { background: var(--surface-2); }
.results .r-name { font-weight: 550; }
.results .r-details { color: var(--muted); font-size: 0.875rem; }

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  min-height: 1.5em;
  margin: 10px 4px 0;
  font-size: 0.875rem;
  color: var(--muted);
}
.utc { margin-left: auto; }
.utc time { font-variant-numeric: tabular-nums; color: var(--text); }

/* ---------- Доска ---------- */

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 20px 22px 18px;
  background: linear-gradient(160deg, var(--day-from), var(--day-to));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow 0.2s, background 0.6s;
}
.card:hover { box-shadow: var(--shadow-lift); }

.card.night {
  --text: var(--night-text);
  --muted: var(--night-muted);
  --border: var(--night-border);
  color: var(--text);
  background: linear-gradient(160deg, var(--night-from), var(--night-to));
}

.card.dragging {
  z-index: 5;
  cursor: grabbing;
  pointer-events: none;
  box-shadow: var(--shadow-lift);
  transform-origin: center;
}
body.sorting { cursor: grabbing; }

.card.flash { animation: flash 0.9s ease-out; }
@keyframes flash {
  0%, 30% { box-shadow: var(--shadow), 0 0 0 4px var(--accent); }
  100% { box-shadow: var(--shadow), 0 0 0 4px transparent; }
}

.card .name {
  margin: 0 32px 0 22px;
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
/* Регион в одну строку (полный текст — в title), а свободное место уходит под него:
   так время в карточках одного ряда стоит на одной линии, даже если название в две строки. */
.card .place {
  margin: 2px 0 auto 22px;
  min-height: 1.5em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 0.875rem;
}

.card .solar {
  margin: 14px 0 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.card .hm { font-size: 3rem; font-weight: 650; line-height: 1; }
.card .sec { font-size: 1.5rem; font-weight: 500; color: var(--muted); }

.meta {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}
.meta div { display: flex; justify-content: space-between; gap: 12px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.meta dt, .meta .coords span { white-space: nowrap; }

.handle, .remove {
  position: absolute;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.handle:hover, .remove:hover { color: var(--text); background: var(--border); }

.handle {
  top: 22px;
  left: 12px;
  width: 22px;
  height: 26px;
  cursor: grab;
  touch-action: none; /* на сенсорных экранах тянем только за ручку, карточка остаётся прокручиваемой */
}
.handle svg { width: 8px; height: 13px; fill: currentColor; }

.remove { top: 14px; right: 14px; width: 30px; height: 30px; }
.remove svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* Компактные карточки */
body.compact .meta { display: none; }
body.compact .card { padding-bottom: 20px; }
body.compact .card p.solar { margin-bottom: 0; } /* p — чтобы перебить отступ аналогового вида */
body.compact .board { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* ---------- Аналоговые часы ---------- */

.clock { display: none; }

body.analog .clock {
  display: block;
  width: 168px;
  margin: 18px auto 6px;
}
body.analog .card .solar { margin: 0 0 14px; text-align: center; }
body.analog .card .hm,
body.analog .card .sec { font-size: 0.95rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }

.clock svg { display: block; width: 100%; height: auto; overflow: visible; }
.clock .face { fill: var(--face-day); filter: drop-shadow(0 2px 6px rgb(0 0 0 / 0.12)); }
.clock .hands { stroke: var(--face-day-ink); stroke-linecap: round; }
.clock .numbers { fill: var(--face-day-ink); font: 500 11px system-ui, -apple-system, sans-serif; }
.clock.night .face { fill: var(--face-night); filter: drop-shadow(0 2px 6px rgb(0 0 0 / 0.35)); }
.clock.night .hands { stroke: var(--face-night-ink); }
.clock.night .numbers { fill: var(--face-night-ink); }
.clock .second { stroke: var(--second-hand); }
.clock .pin { fill: var(--face-day); stroke: var(--second-hand); }
.clock.night .pin { fill: var(--face-night); }

/* ---------- Пустая доска ---------- */

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty[hidden] { display: none; }
.empty-sun { width: 44px; height: 44px; }
.empty p { margin: 6px 0; }
.empty-title { color: var(--text); font-size: 1.15rem; font-weight: 600; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}
.chips button {
  padding: 8px 16px;
  color: var(--text);
  font-size: 0.925rem;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.chips button:hover { border-color: var(--accent); background: var(--accent-soft); }
.chips button:disabled { opacity: 0.5; cursor: progress; }

/* ---------- Пояснение ---------- */

.explainer { padding: 80px 0 24px; }

.explainer h2 {
  margin: 0 0 24px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.explainer-grid {
  display: grid;
  gap: 16px;
}
@media (min-width: 640px) {
  .explainer-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1040px) {
  .explainer-grid { grid-template-columns: repeat(4, 1fr); }
}
.explainer article {
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.explainer-num {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.explainer h3 { margin: 0 0 8px; font-size: 1.05rem; font-weight: 650; }
.explainer article p:not(.explainer-num) { margin: 0; color: var(--muted); font-size: 0.95rem; }
.explainer article p.eot-today {
  margin-top: 12px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 0.9rem;
}

/* ---------- Подвал ---------- */

.footer {
  padding-top: 40px;
  padding-bottom: 40px;
  color: var(--muted);
  font-size: 0.85rem;
}
.footer p { margin: 0; padding-top: 20px; border-top: 1px solid var(--border); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
