:root {
  --bg-top: #f2f4ef;
  --bg-bottom: #c8d6e5;
  --ink-1: #11231a;
  --ink-2: #2e4a3a;
  --card: rgba(255, 255, 255, 0.74);
  --card-border: rgba(17, 35, 26, 0.12);
  --accent: #d97a2b;
  --accent-dark: #aa5314;
  --shadow: 0 18px 45px rgba(28, 45, 39, 0.13);
}

body.theme-dark {
  --bg-top: #1a2520;
  --bg-bottom: #1a2430;
  --ink-1: #dbe5df;
  --ink-2: #a8bbb0;
  --card: rgba(24, 35, 31, 0.76);
  --card-border: rgba(205, 220, 212, 0.14);
  --accent: #df8d45;
  --accent-dark: #c56f25;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
}

body.theme-dark .tabs {
  background: rgba(34, 46, 40, 0.72);
}

body.theme-dark .tab-link {
  color: #bdd0c4;
}

body.theme-dark .theme-toggle-btn {
  background: rgba(22, 36, 30, 0.95);
}

body.theme-dark .theme-toggle-btn:hover {
  background: rgba(29, 46, 38, 0.98);
}

body.theme-dark .weather,
body.theme-dark .search-form input,
body.theme-dark .link-form input,
body.theme-dark .prefs-row select,
body.theme-dark .edit-mode-btn,
body.theme-dark .link-card,
body.theme-dark .link-dialog,
body.theme-dark #cancelLinkBtn {
  background: rgba(39, 53, 47, 0.85);
  color: var(--ink-1);
}

body.theme-dark .link-card p,
body.theme-dark .links-hint,
body.theme-dark .date,
body.theme-dark .weather-title,
body.theme-dark .settings-subtitle,
body.theme-dark .prefs-row label {
  color: #9fb3a7;
}

body.theme-dark .link-card:not(.is-editing):hover {
  border-color: rgba(188, 205, 196, 0.26);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.18);
}

body.theme-dark .add-link-btn:disabled {
  background: rgba(151, 163, 156, 0.35);
  color: rgba(238, 244, 239, 0.55);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--ink-1);
  background:
    radial-gradient(circle at 15% 10%, rgba(217, 122, 43, 0.18), transparent 40%),
    radial-gradient(circle at 90% 85%, rgba(17, 35, 26, 0.15), transparent 38%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

.topbar {
  width: min(1000px, calc(100% - 2rem));
  margin: 1.1rem auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tabs {
  display: inline-flex;
  gap: 0.45rem;
  padding: 0.35rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
}

.tab-link {
  text-decoration: none;
  color: var(--ink-2);
  font-weight: 700;
  border-radius: 10px;
  padding: 0.42rem 0.75rem;
}

.tab-link.active {
  background: var(--accent);
  color: #fff;
}

.theme-toggle-btn {
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink-1);
  padding: 0.62rem 0.85rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.theme-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.95);
}

.dashboard {
  width: min(1000px, calc(100% - 2rem));
  margin: 2.4rem auto;
  display: grid;
  gap: 1.4rem;
}

.hero,
.search-section,
.prefs-section,
.links-section {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(7px);
}

.hero {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  padding: 1.4rem;
  align-items: center;
  animation: enter 0.6s ease;
}

.date {
  margin: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 500;
}

.time {
  margin: 0.35rem 0 0;
  font-size: clamp(2rem, 5.5vw, 4rem);
  line-height: 1;
}

.weather {
  border-radius: 16px;
  border: 1px solid var(--card-border);
  padding: 0.95rem;
  background: rgba(255, 255, 255, 0.56);
}

.weather-title {
  margin: 0;
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.weather-main {
  margin: 0.35rem 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.weather-sub {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.88rem;
}

.search-section {
  position: relative;
  z-index: 30;
  padding: 1.1rem;
  animation: enter 0.8s ease;
}

.prefs-section {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: flex-start;
  padding: 0.9rem 1.1rem;
  animation: enter 0.9s ease;
}

.prefs-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.prefs-row label {
  font-size: 0.9rem;
  color: var(--ink-2);
}

.prefs-row select {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  font: inherit;
  padding: 0.42rem 0.62rem;
}

.search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  position: relative;
}

.search-suggestions {
  position: absolute;
  top: calc(100% + 0.42rem);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 24px rgba(17, 35, 26, 0.12);
  z-index: 20;
}

.search-suggestion-item {
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  color: var(--ink-1);
  cursor: pointer;
}

.search-suggestion-item:hover,
.search-suggestion-item.active {
  background: rgba(217, 122, 43, 0.14);
}

body.theme-dark .search-suggestions {
  background: rgba(39, 53, 47, 0.96);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.26);
}

body.theme-dark .search-suggestion-item:hover,
body.theme-dark .search-suggestion-item.active {
  background: rgba(223, 141, 69, 0.2);
}

.search-form input,
.search-form button,
.link-form input,
.link-form button {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  font: inherit;
}

.search-form input,
.link-form input {
  padding: 0.8rem 0.95rem;
  background: rgba(255, 255, 255, 0.9);
}

.search-form button,
.add-link-btn,
.link-form button[type="submit"] {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.8rem 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease;
}

.search-form button:hover,
.add-link-btn:hover,
.link-form button[type="submit"]:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

.links-section {
  padding: 1.1rem;
  animation: enter 1s ease;
}

.settings-dashboard {
  width: min(1000px, calc(100% - 2rem));
}

.settings-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(7px);
  padding: 1.2rem;
}

.settings-card h1 {
  margin: 0;
}

.settings-subtitle {
  margin: 0.4rem 0 1rem;
  color: var(--ink-2);
}

.version-footer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--card-border);
  text-align: center;
}

.version-text {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ink-2);
  opacity: 0.7;
  letter-spacing: 0.5px;
}

.links-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.85rem;
}

.links-head h2 {
  margin: 0;
}

.links-actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.links-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-2);
}

.edit-mode-btn {
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink-1);
  padding: 0.72rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.edit-mode-btn.active {
  background: var(--ink-1);
  color: #fff;
}

.add-link-btn {
  border-radius: 12px;
  display: none;
}

.add-link-btn:disabled {
  background: #bfc9c3;
  color: #f5f6f7;
  cursor: not-allowed;
  transform: none;
}

.links-section.edit-mode .add-link-btn {
  display: inline-block;
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.75rem;
}

.link-card {
  position: relative;
  border: 1px solid var(--card-border);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.85);
  padding: 0.8rem;
  min-height: 94px;
  transition: transform 220ms cubic-bezier(0.2, 0.85, 0.3, 1), border-color 220ms ease, box-shadow 220ms ease;
  animation: cardFadeIn 360ms ease both;
}

.link-card:not(.is-editing):hover {
  transform: translateY(-2px);
  border-color: rgba(17, 35, 26, 0.24);
  box-shadow: 0 8px 18px rgba(17, 35, 26, 0.08);
}

.links-grid .link-card:nth-child(2) {
  animation-delay: 50ms;
}

.links-grid .link-card:nth-child(3) {
  animation-delay: 90ms;
}

.links-grid .link-card:nth-child(4) {
  animation-delay: 130ms;
}

.links-grid .link-card:nth-child(5) {
  animation-delay: 170ms;
}

.link-card.is-editing {
  padding-top: 2rem;
  border-color: rgba(17, 35, 26, 0.35);
  box-shadow: inset 0 0 0 1px rgba(17, 35, 26, 0.14);
}

.link-card[draggable="true"] {
  cursor: move;
}

.link-card.dragging {
  opacity: 0.5;
}

.link-card a {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: var(--ink-1);
  font-weight: 700;
}

.link-card.is-editing .link-card-link {
  pointer-events: none;
}

.link-title-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 220ms ease;
}

.link-card:not(.is-editing):hover .link-title-row {
  transform: translateX(1px);
}

.link-favicon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
}

.link-card p {
  margin: 0.35rem 0 0;
  color: var(--ink-2);
  font-size: 0.86rem;
  font-family: "IBM Plex Mono", monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-actions-inline {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  display: none;
  gap: 0.55rem;
}

.link-card.is-editing .link-actions-inline {
  display: inline-flex;
}

.remove-link,
.edit-link {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0;
}

.edit-link {
  color: var(--ink-2);
}

.remove-link {
  color: #7b0f0f;
}

.link-dialog {
  border: none;
  border-radius: 16px;
  width: min(420px, calc(100% - 2rem));
  padding: 0;
}

.link-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.link-form {
  display: grid;
  gap: 0.55rem;
  padding: 1.1rem;
}

.link-form h3 {
  margin: 0 0 0.4rem;
}

.link-form menu {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin: 0.45rem 0 0;
  padding: 0;
}

#cancelLinkBtn {
  background: #f3f4f5;
  color: var(--ink-1);
}

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

@keyframes enter {
  from {
    transform: translateY(7px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .topbar {
    width: min(1000px, calc(100% - 1.25rem));
    margin-top: 0.8rem;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .prefs-section {
    flex-wrap: wrap;
  }

  .links-actions {
    flex-direction: column;
    align-items: flex-end;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .dashboard {
    width: min(1000px, calc(100% - 1.25rem));
    margin: 1.2rem auto;
  }
}
