:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --text: #18222e;
  --muted: #5b6b7b;
  --accent: #ff8a2b;
  --accent-2: #ffb347;
  --border: #e6ebf2;
  --shadow: 0 4px 18px rgba(20, 40, 70, 0.07);
  --radius: 16px;
}
[data-theme="dark"] {
  --bg: #0f141b;
  --card: #19212c;
  --card-2: #131a23;
  --text: #eef3f8;
  --muted: #93a3b5;
  --accent: #ff9b45;
  --accent-2: #ffb863;
  --border: #25303d;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
.app { max-width: 700px; margin: 0 auto; padding: 18px 16px 48px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.brand { font-size: 1.3rem; margin: 0; letter-spacing: -0.02em; font-weight: 800; }
.brand .accent { color: var(--accent); }
.tools { display: flex; gap: 8px; }
.tagline { font-size: 0.82rem; color: var(--muted); margin: 0 0 14px; }

.icon-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; width: 42px; height: 42px; font-size: 1.05rem;
  cursor: pointer; display: grid; place-items: center; flex: none;
  transition: transform 0.08s ease;
}
.icon-btn:active { transform: scale(0.93); }

.search { position: relative; margin-bottom: 12px; }
.search-field { position: relative; }
.search input {
  width: 100%; padding: 13px 46px 13px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 1rem;
}
.search input:focus { outline: 2px solid var(--accent-2); border-color: transparent; }
.star-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border: none; background: transparent; color: var(--accent);
  font-size: 1.3rem; cursor: pointer; border-radius: 9px; display: grid; place-items: center;
}
.star-btn[hidden] { display: none; }
.results button .x { float: right; color: var(--muted); font-weight: 700; }

.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); z-index: 30; overflow: hidden; display: none;
}
.results.open { display: block; }
.results button {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border: none;
  background: none; color: var(--text); cursor: pointer; font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
}
.results button:last-child { border-bottom: none; }
.results button:hover { background: var(--card-2); }
.results .muted { color: var(--muted); font-size: 0.8rem; }

/* Profile selector */
.profiles {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  margin-bottom: 14px; scrollbar-width: none;
}
.profiles::-webkit-scrollbar { display: none; }
.profile {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 9px 12px; font-size: 0.85rem; cursor: pointer; white-space: nowrap;
}
.profile .ico { font-size: 1.2rem; line-height: 1; }
.profile.active { background: var(--accent); border-color: var(--accent); color: #1c1305; font-weight: 600; }
.profile.edit { color: var(--muted); }

.context {
  display: flex; align-items: center; gap: 8px; min-height: 0;
  font-size: 0.82rem; color: var(--muted); margin: 0 0 12px;
}
.context:empty { margin: 0; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.today-card {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1c1305; border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.today-top { display: flex; justify-content: space-between; align-items: flex-start; }
.today-label { font-weight: 700; text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.08em; opacity: 0.85; }
.today-temp { font-size: 3.1rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.today-temp small { font-size: 1.1rem; font-weight: 600; opacity: 0.7; }
.today-emoji { font-size: 2.8rem; line-height: 1; }
.today-meta { font-size: 0.85rem; margin-top: 4px; }
.today-source { font-size: 0.72rem; opacity: 0.85; margin-top: 8px; }

.grid { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.day {
  min-width: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 14px; cursor: pointer;
}
.day-row { display: grid; grid-template-columns: 44px 28px 1fr auto; align-items: center; gap: 10px; min-width: 0; }
.day.changed { animation: pop 0.5s ease; }
@keyframes pop {
  0% { box-shadow: 0 0 0 0 var(--accent-2); }
  40% { box-shadow: 0 0 0 3px var(--accent-2); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.day .dow { font-weight: 700; }
.day .date { font-size: 0.72rem; color: var(--muted); }
.day .emoji { font-size: 1.45rem; text-align: center; }
.day .mid { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.day .meta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .src { font-size: 0.7rem; color: var(--accent); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .src:hover { text-decoration: underline; }
.today-source .src-link { color: inherit; text-decoration: underline; }
.day .temps { text-align: right; white-space: nowrap; }
.day .tmax { font-weight: 700; font-size: 1.05rem; }
.day .tmin { color: var(--muted); font-size: 0.9rem; }

.hours {
  display: flex; gap: 12px; overflow-x: auto;
  padding: 9px 0 4px; margin-top: 9px; border-top: 1px solid var(--border);
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.hours::-webkit-scrollbar { height: 6px; }
.hours::-webkit-scrollbar-track { background: transparent; }
.hours::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.today-card .hours { border-top-color: rgba(0, 0, 0, 0.15); scrollbar-color: rgba(0, 0, 0, 0.25) transparent; }
.today-card .hours::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.22); }
.hour { flex: none; text-align: center; font-size: 0.72rem; min-width: 46px; }
.hour .h-time { opacity: 0.7; }
.hour .h-emoji { font-size: 1.1rem; }
.hour .h-temp { font-weight: 700; font-size: 0.85rem; }
.hour .h-wind { opacity: 0.7; white-space: nowrap; }

.hint, .notfound { color: var(--muted); text-align: center; padding: 36px 16px; font-size: 0.95rem; }
.notfound { color: var(--text); }

.sources { margin-top: 22px; }
.sources h2 { font-size: 0.85rem; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.source-list { display: flex; flex-wrap: wrap; gap: 7px; }
.src-item {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem;
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 10px;
  color: var(--text); text-decoration: none; background: var(--card);
}
.src-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.src-item .dot.ok { background: #35c26b; }
.src-item .dot.error { background: #e0556b; }
.src-item .tag { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.about { margin-top: 26px; color: var(--muted); }
.about h2 { font-size: 1rem; color: var(--text); margin: 18px 0 6px; }
.about p { font-size: 0.88rem; margin: 0 0 6px; }
.about details { border-top: 1px solid var(--border); padding: 10px 0; font-size: 0.88rem; }
.about summary { cursor: pointer; color: var(--text); font-weight: 600; list-style: none; }
.about summary::-webkit-details-marker { display: none; }
.about summary::before { content: "+ "; color: var(--accent); }
.about details[open] summary::before { content: "– "; }
.about details p { margin: 8px 0 2px; }

.footer { text-align: center; color: var(--muted); font-size: 0.72rem; margin-top: 24px; }

@media (min-width: 720px) {
  .day-row { grid-template-columns: 56px 32px 1fr auto; }
  .day { padding: 12px 16px; }
  .day .tmax { font-size: 1.1rem; }
  .today-temp { font-size: 3.4rem; }
}

/* Modal */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; background: rgba(10, 18, 28, 0.55);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-card {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px 28px;
}
@media (min-width: 600px) { .modal { align-items: center; } .modal-card { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { font-size: 1.1rem; margin: 0; }
.modal h3 { font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 18px 0 8px; }
.prow {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.prow .pname { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.prow .fields { display: flex; gap: 8px; grid-column: 1 / -1; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; font-size: 0.68rem; color: var(--muted); gap: 3px; }
.field input { width: 72px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); font-size: 0.9rem; }
.field input.name-input { width: 130px; }
.linkbtn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 0.8rem; padding: 4px; }
.linkbtn.reset { font-size: 1.2rem; line-height: 1; padding: 2px 6px; }
.btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 9px 14px; font-size: 0.9rem; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1c1305; font-weight: 600; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
