:root {
  color-scheme: light;
  --bg: #eef3f8;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: rgba(255, 255, 255, 0.92);
  --surface-soft: rgba(235, 241, 247, 0.86);
  --text: #111827;
  --muted: #64748b;
  --line: rgba(148, 163, 184, 0.34);
  --accent: #1976d2;
  --accent-dark: #0f5ca8;
  --accent-soft: #1976d224;
  --danger: #d33d3d;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(25, 118, 210, 0.14), transparent 30%),
    radial-gradient(circle at 92% 10%, rgba(14, 165, 139, 0.12), transparent 32%),
    linear-gradient(145deg, #eef5fc 0%, #f7fafc 58%, #edf7f3 100%);
}

button,
input,
select {
  font: inherit;
}

button,
.ghost-button {
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.top-nav {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 0;
  position: relative;
  z-index: 70;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.nav-menu {
  position: relative;
}

.nav-menu + .nav-menu {
  margin-left: 4px;
}

.nav-trigger {
  display: grid;
  place-items: center;
  min-width: 128px;
  min-height: 54px;
  padding: 8px 18px;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  letter-spacing: 0;
  border: 0;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.20);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(22px) saturate(1.35);
}

.nav-trigger:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.30);
  transform: none;
}

.nav-trigger::after {
  content: "";
  width: 0;
  height: 3px;
  align-self: end;
  background: var(--accent);
  transition: width 160ms ease;
}

.nav-menu:hover .nav-trigger::after,
.nav-menu:focus-within .nav-trigger::after {
  width: 100%;
}

.nav-submenu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 184px;
  padding: 10px 14px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  pointer-events: none;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.30);
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(26px) saturate(1.45);
  transition: opacity 160ms ease, transform 160ms ease, visibility 160ms ease;
}

.nav-menu:hover .nav-submenu,
.nav-menu:focus-within .nav-submenu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.nav-submenu button,
.nav-submenu a {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 42px;
  border: 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 0 4px;
  text-decoration: none;
}

.nav-submenu button:hover,
.nav-submenu a:hover {
  color: var(--accent-dark);
  background: transparent;
  transform: none;
}

.nav-submenu > :last-child {
  border-bottom: 0;
}

button:hover,
.ghost-button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.ghost-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.38);
  backdrop-filter: blur(18px);
}

.ghost-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.76);
}

.danger {
  background: #fff0f0;
  color: var(--danger);
}

.danger:hover {
  background: #ffe1e1;
}

.background-layer,
.background-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.background-layer {
  z-index: -3;
  background:
    radial-gradient(circle at 20% 0%, rgba(25, 118, 210, 0.14), transparent 30%),
    radial-gradient(circle at 92% 10%, rgba(14, 165, 139, 0.12), transparent 32%),
    linear-gradient(145deg, #eef5fc 0%, #f7fafc 58%, #edf7f3 100%);
}

.background-layer img,
.background-layer video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.background-overlay {
  z-index: -2;
  backdrop-filter: blur(0.5px);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface-strong);
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(24px, 4vw, 36px);
  backdrop-filter: blur(22px);
}

.brand-kicker {
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

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

.login-panel h1 {
  margin-bottom: 22px;
  font-size: clamp(30px, 6vw, 40px);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--surface-soft);
  border-radius: 8px;
}

.auth-tabs button {
  min-height: 36px;
  color: var(--muted);
  background: transparent;
}

.auth-tabs button.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.login-form,
.dialog-body {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inline-check input {
  width: 18px;
  min-height: 18px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input[type="range"] {
  padding: 0;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.14);
}

.form-error {
  border-radius: 8px;
  background: #fff0f0;
  color: #af2626;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.login-tip,
.dialog-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 2px 0 0;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 8px 0 56px;
}

.topbar {
  position: relative;
  z-index: 60;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: clamp(28px, 5vw, 48px);
}

.title-block {
  min-width: 0;
}

.topbar h1 {
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.05;
  margin-bottom: 0;
  word-break: break-word;
}

.editable-title {
  position: relative;
}

.hover-edit {
  opacity: 0;
  pointer-events: none;
  min-height: 30px;
  padding: 5px 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  font-size: 12px;
  flex: 0 0 auto;
}

.editable-title:hover .hover-edit,
.editable-title:focus-within .hover-edit {
  opacity: 1;
  pointer-events: auto;
}

.title-block {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 4px;
}

.title-block .brand-kicker {
  grid-column: 1 / -1;
}

.title-block .hover-edit {
  align-self: center;
  white-space: nowrap;
}

.search-panel {
  margin: 0 auto clamp(28px, 5vw, 42px);
  width: min(820px, 100%);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(120px, 150px) 1fr 96px;
  background: var(--surface-strong);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px;
  gap: 10px;
  backdrop-filter: blur(22px);
}

.search-form input,
.search-form select {
  border-color: transparent;
  background: var(--surface-soft);
}

.nav-board {
  display: grid;
  gap: 18px;
}

.board-toolbar,
.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.board-toolbar {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.board-title-group,
.board-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.board-title-group {
  width: max-content;
  max-width: 100%;
}

.board-toolbar h2,
.category-header h3 {
  margin-bottom: 0;
}

.board-toolbar h2 {
  font-size: clamp(20px, 3vw, 25px);
}

.inline-title-input {
  width: auto;
  max-width: min(420px, 100%);
  min-height: auto;
  border: 0;
  border-bottom: 2px solid var(--accent);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  font-weight: 800;
  padding: 0 0 5px;
}

.title-block .inline-title-input {
  grid-column: 1 / 2;
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.05;
}

.board-toolbar .inline-title-input {
  font-size: clamp(20px, 3vw, 25px);
}

.category-list {
  display: grid;
  gap: 22px;
}

.category {
  display: grid;
  gap: 14px;
  padding: 16px 0;
}

.category[draggable="true"] {
  cursor: grab;
}

.category-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.category-actions button {
  min-height: 34px;
  padding: 7px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid var(--line);
}

.category-actions button:first-child,
.board-actions button {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.category-actions button:first-child:hover,
.board-actions button:hover {
  background: var(--accent-dark);
}

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(96px, 11vw, 128px), 1fr));
  gap: clamp(10px, 1.6vw, 16px);
  min-height: 112px;
}

.site-tile {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 12px;
  aspect-ratio: 1 / 1;
  min-height: 104px;
  padding: 16px 10px;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(18px);
  cursor: grab;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background 150ms ease;
  touch-action: manipulation;
}

.site-tile:hover {
  transform: translateY(-3px);
  border-color: rgba(25, 118, 210, 0.35);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 34px rgba(15, 23, 42, 0.14);
}

.site-tile:active {
  cursor: grabbing;
}

.site-tile img {
  width: clamp(40px, 6vw, 50px);
  height: clamp(40px, 6vw, 50px);
  border-radius: 8px;
  object-fit: contain;
}

.site-tile span {
  width: 100%;
  min-height: 20px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-tools {
  position: absolute;
  inset: auto 8px 8px 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tile-tool {
  min-height: 28px;
  padding: 4px 6px;
  font-size: 12px;
  background: rgba(238, 243, 248, 0.94);
  color: var(--text);
}

.tile-tool:hover {
  background: #dde8f3;
}

.tile-tool.danger {
  color: var(--danger);
}

.category-empty,
.empty-state {
  color: var(--muted);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 220px;
  border: 1px dashed rgba(100, 116, 139, 0.4);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.44);
  backdrop-filter: blur(12px);
}

.dragging {
  opacity: 0.42;
  transform: scale(0.96);
}

.edit-dialog {
  width: min(540px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.wide-dialog {
  width: min(760px, calc(100% - 28px));
}

.edit-dialog::backdrop {
  background: rgba(18, 27, 39, 0.42);
  backdrop-filter: blur(4px);
}

.dialog-body {
  padding: 22px;
  background: rgba(255, 255, 255, 0.96);
}

.dialog-body header,
.dialog-body footer,
.inline-input {
  display: flex;
  gap: 10px;
  align-items: center;
}

.dialog-body header,
.dialog-body footer {
  justify-content: space-between;
}

.dialog-body h2 {
  margin-bottom: 0;
  font-size: 20px;
}

.stack-form {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.stack-form h3 {
  margin: 0;
  font-size: 16px;
}

.stack-form button {
  justify-self: end;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  min-height: 0;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 24px;
}

.inline-input input {
  flex: 1;
}

.inline-input button {
  width: 84px;
  flex: 0 0 auto;
}

.background-library {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.background-library header {
  align-items: center;
}

.background-library h3 {
  margin: 0;
  font-size: 16px;
}

.background-library .ghost-button {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.background-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  max-height: 320px;
  overflow: auto;
  padding-right: 4px;
}

.library-empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.background-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.84);
  padding: 8px;
}

.background-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.background-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: #dbe4ef;
}

.background-preview img,
.background-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.background-info {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.background-info strong,
.background-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.background-info strong {
  font-size: 13px;
}

.background-info span {
  color: var(--muted);
  font-size: 12px;
}

.background-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.background-actions button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.users-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr 150px auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.84);
  padding: 10px;
}

.user-name {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.user-name strong,
.user-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-name span {
  color: var(--muted);
  font-size: 12px;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.color-swatches button {
  min-height: 42px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: var(--swatch);
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100% - 24px, 1180px);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-nav {
    justify-content: flex-start;
  }

  .title-block {
    grid-template-columns: auto;
    justify-items: start;
  }

  .title-block .hover-edit {
    margin-top: 4px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-bottom: 32px;
  }

  .top-nav,
  .board-toolbar,
  .category-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-nav,
  .nav-menu,
  .nav-trigger,
  .board-toolbar > button,
  .board-actions,
  .board-actions > button,
  .category-actions > button {
    width: 100%;
  }

  .nav-submenu {
    position: static;
    min-width: 0;
    opacity: 1;
    visibility: visible;
    transform: none;
    pointer-events: auto;
    box-shadow: none;
    border-left: 0;
    border-right: 0;
    display: none;
  }

  .nav-menu:hover .nav-submenu,
  .nav-menu:focus-within .nav-submenu {
    display: grid;
  }

  .board-title-group {
    width: max-content;
    justify-content: flex-start;
  }

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

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

  .site-tile {
    min-height: 96px;
    padding: 12px 8px;
  }

  .site-tile span {
    font-size: 13px;
  }

  .dialog-body footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .inline-input {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-input button {
    width: 100%;
  }

  .background-list {
    grid-template-columns: 1fr;
    max-height: 360px;
  }

  .user-row {
    grid-template-columns: 1fr;
  }

  .stack-form button {
    justify-self: stretch;
  }
}

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