:root {
  color-scheme: light;
  --background: #f4f7fb;
  --surface: #ffffff;
  --surface-subtle: #f8faff;
  --text: #172033;
  --text-muted: #67738b;
  --primary: #5b55e7;
  --primary-dark: #4842c7;
  --primary-soft: #eeedff;
  --danger: #dc5262;
  --danger-soft: #fff0f2;
  --border: #e3e8f2;
  --shadow: 0 12px 35px rgba(28, 39, 68, 0.08);
  --shadow-hover: 0 18px 40px rgba(28, 39, 68, 0.13);
  --radius-large: 22px;
  --radius-medium: 15px;
  --radius-small: 10px;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(91, 85, 231, 0.08), transparent 28rem),
    var(--background);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 54px 0 72px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  place-items: center;
  color: #ffffff;
  border-radius: 18px;
  background: linear-gradient(145deg, #716cff, var(--primary-dark));
  box-shadow: 0 10px 25px rgba(91, 85, 231, 0.26);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  line-height: 1.15;
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.header-description {
  margin-bottom: 0;
  color: var(--text-muted);
}

.add-section,
.library-section {
  border: 1px solid rgba(227, 232, 242, 0.9);
  border-radius: var(--radius-large);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.add-section {
  padding: 28px;
}

.section-heading,
.library-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.section-heading {
  margin-bottom: 24px;
}

.shortcut-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.bookmark-form {
  display: grid;
  grid-template-columns: 1fr 1.45fr 0.8fr auto;
  align-items: start;
  gap: 16px;
}

.form-field {
  min-width: 0;
}

.form-field label {
  display: block;
  margin-bottom: 8px;
  color: #3d4860;
  font-size: 0.82rem;
  font-weight: 700;
}

.form-field input,
.form-field select {
  width: 100%;
  height: 49px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  outline: none;
  background: var(--surface-subtle);
  color: var(--text);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.form-field input {
  padding: 0 14px;
}

.form-field select {
  appearance: none;
  padding: 0 38px 0 14px;
}

.form-field input::placeholder {
  color: #9aa4b7;
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(91, 85, 231, 0.11);
}

.form-field input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px rgba(220, 82, 98, 0.09);
}

.select-wrapper {
  position: relative;
}

.select-wrapper::after {
  position: absolute;
  top: 50%;
  right: 15px;
  width: 7px;
  height: 7px;
  border-right: 2px solid #778197;
  border-bottom: 2px solid #778197;
  content: "";
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}

.field-error {
  display: block;
  min-height: 18px;
  padding-top: 4px;
  color: var(--danger);
  font-size: 0.76rem;
}

.primary-button {
  display: inline-flex;
  height: 49px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  align-self: start;
  margin-top: 28px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-small);
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(91, 85, 231, 0.22);
  font-weight: 750;
  white-space: nowrap;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease;
}

.primary-button:hover {
  background: var(--primary-dark);
  box-shadow: 0 10px 22px rgba(91, 85, 231, 0.28);
  transform: translateY(-1px);
}

.primary-button:active {
  transform: translateY(0);
}

.library-section {
  min-height: 330px;
  margin-top: 24px;
  padding: 28px;
}

.library-heading {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.bookmark-count {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.8rem;
}

.bookmark-count strong {
  font-size: 1rem;
}

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

.search-toolbar {
  margin-bottom: 24px;
}

.search-field {
  position: relative;
}

.search-field::before {
  position: absolute;
  top: 50%;
  left: 17px;
  width: 12px;
  height: 12px;
  border: 2px solid #8490a5;
  border-radius: 50%;
  content: "";
  pointer-events: none;
  transform: translateY(-60%);
}

.search-field::after {
  position: absolute;
  top: calc(50% + 6px);
  left: 29px;
  width: 7px;
  height: 2px;
  border-radius: 2px;
  background: #8490a5;
  content: "";
  pointer-events: none;
  transform: rotate(45deg);
  transform-origin: left center;
}

.search-field input {
  width: 100%;
  height: 50px;
  padding: 0 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  color: var(--text);
  background: var(--surface-subtle);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.search-field input::placeholder {
  color: #929caf;
}

.search-field input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(91, 85, 231, 0.11);
}

.bookmark-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.bookmark-card {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 156px;
  flex-direction: column;
  padding: 20px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  background: var(--surface);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.bookmark-card::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  border-radius: 4px;
  background: var(--card-accent, var(--primary));
  content: "";
}

.bookmark-card:hover,
.bookmark-card:focus-within {
  border-color: #d5d9e9;
  box-shadow: var(--shadow-hover);
  transform: translateY(-3px);
}

.bookmark-link {
  color: inherit;
  text-decoration: none;
}

.bookmark-link::after {
  position: absolute;
  inset: 0;
  content: "";
}

.bookmark-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.bookmark-title {
  margin-bottom: 6px;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.external-arrow {
  flex: 0 0 auto;
  color: #8f98aa;
  font-size: 1.1rem;
  transition:
    color 160ms ease,
    transform 160ms ease;
}

.bookmark-card:hover .external-arrow {
  color: var(--primary);
  transform: translate(2px, -2px);
}

.bookmark-domain {
  margin-bottom: auto;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  padding: 5px 9px;
  border-radius: 7px;
  color: var(--card-accent-dark, var(--primary-dark));
  background: var(--card-accent-soft, var(--primary-soft));
  font-size: 0.73rem;
  font-weight: 750;
}

.delete-button {
  position: relative;
  z-index: 1;
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: #9aa3b4;
  background: transparent;
  font-size: 1.05rem;
  transition:
    color 150ms ease,
    background-color 150ms ease;
}

.delete-button:hover,
.delete-button:focus-visible {
  color: var(--danger);
  background: var(--danger-soft);
  outline: none;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 14px;
  place-items: center;
  border: 1px solid #dedcfb;
  border-radius: 18px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 2rem;
  font-weight: 300;
  transform: rotate(-18deg);
}

.empty-state h3 {
  margin-bottom: 6px;
  font-size: 1rem;
}

.empty-state p {
  max-width: 360px;
  margin-bottom: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.search-empty-state {
  display: grid;
  min-height: 190px;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-medium);
  color: var(--text-muted);
  background: var(--surface-subtle);
  text-align: center;
}

.search-empty-state[hidden] {
  display: none;
}

.search-empty-state p {
  margin: 0;
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 32px);
  padding: 13px 17px;
  border: 1px solid #dce5df;
  border-radius: 12px;
  color: #244a32;
  background: #f5fff8;
  box-shadow: 0 15px 35px rgba(28, 39, 68, 0.16);
  font-size: 0.87rem;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition:
    opacity 200ms ease,
    transform 200ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: #39a162;
  font-size: 0.75rem;
}

@media (max-width: 940px) {
  .bookmark-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-button {
    align-self: end;
    margin-top: 28px;
  }

  .bookmark-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 24px, 1180px);
    padding: 28px 0 48px;
  }

  .app-header {
    align-items: flex-start;
    margin-bottom: 24px;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
    border-radius: 15px;
  }

  .header-description {
    font-size: 0.88rem;
  }

  .add-section,
  .library-section {
    padding: 20px;
    border-radius: 18px;
  }

  .section-heading,
  .library-heading {
    align-items: flex-start;
  }

  .shortcut-hint {
    display: none;
  }

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

  .primary-button {
    width: 100%;
    margin-top: 0;
  }

  .bookmark-card {
    min-height: 148px;
  }

  .search-toolbar {
    margin-bottom: 20px;
  }

  .search-field input {
    height: 48px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
    left: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
