:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #11151b;
  --panel-elevated: #151a21;
  --line: #252c35;
  --line-soft: #1d242d;
  --text: #f2f5f8;
  --muted: #97a3b3;
  --muted-strong: #c1cad6;
  --accent: #44d19b;
  --accent-hover: #57ddb0;
  --accent-ink: #06120e;
  --danger: #ff7070;
  --danger-bg: rgba(255, 112, 112, 0.09);
  --warning: #e7bd62;
  --warning-bg: rgba(231, 189, 98, 0.11);
  --success-bg: rgba(68, 209, 155, 0.1);
  --input: #0d1117;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 760;
  white-space: nowrap;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

button:hover {
  background: var(--accent-hover);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

button.secondary {
  border: 1px solid var(--line);
  background: #121820;
  color: var(--text);
}

button.secondary:hover {
  border-color: #354353;
  background: #202936;
}

button.danger {
  border: 1px solid rgba(255, 107, 107, 0.4);
  background: transparent;
  color: #ff9f9f;
}

button.danger:hover {
  border-color: rgba(255, 107, 107, 0.64);
  background: var(--danger-bg);
}

button.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--input);
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

input {
  min-height: 44px;
  padding: 0 13px;
}

textarea {
  min-height: 132px;
  max-height: 240px;
  padding: 12px 13px;
  resize: vertical;
  line-height: 1.45;
}

select {
  min-height: 44px;
  padding: 0 36px 0 13px;
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: #667386;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(64, 211, 154, 0.72);
  background: #0d1218;
  box-shadow: 0 0 0 3px rgba(64, 211, 154, 0.14);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 3.6vw, 36px);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.login-panel {
  padding: 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 18px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  font-size: 22px;
}

.login-subtitle,
.topbar-subtitle {
  margin-top: 8px;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

label span,
dt,
.muted {
  color: var(--muted);
}

label span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
}

.app-page {
  padding-bottom: 32px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  width: min(1500px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 820;
  letter-spacing: 0;
  text-transform: uppercase;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  width: min(1500px, calc(100% - 48px));
  margin: 0 auto;
}

.additions-section {
  display: grid;
  gap: 16px;
}

.additions-section[hidden] {
  display: none;
}

#add-toggle-button.active {
  background: #d9efe7;
  color: #07130f;
}

#archive-toggle-button.active {
  border-color: #d9efe7;
  background: #d9efe7;
  color: #07130f;
}

.panel {
  padding: 20px;
}

.add-panel {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
  align-items: end;
}

.add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.add-panel .message {
  grid-column: 1 / -1;
}

.import-panel {
  display: grid;
  gap: 12px;
}

.import-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 12px;
  align-items: start;
}

.import-actions {
  display: grid;
  gap: 10px;
}

.import-actions .message {
  min-height: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.table-panel {
  padding-bottom: 0;
  min-height: min(760px, calc(100vh - 132px));
}

.table-controls {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 180px 220px;
  gap: 10px;
  margin-bottom: 14px;
}

.table-wrap {
  max-height: min(680px, calc(100vh - 260px));
  min-height: min(540px, calc(100vh - 320px));
  margin: 0 -20px;
  overflow: auto;
  border-top: 1px solid var(--line-soft);
  scrollbar-color: #465467 #121820;
  scrollbar-width: thin;
}

table {
  width: 100%;
  min-width: 1320px;
  border-collapse: separate;
  border-spacing: 0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #11151b;
}

th,
td {
  padding: 15px 20px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  color: #e7edf5;
}

td:first-child {
  font-weight: 720;
  color: var(--text);
}

.provider-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 9px;
  background: #0f141b;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.provider-badge.outlook {
  border-color: #304761;
  background: #101923;
  color: #b8d4f4;
}

.provider-badge.rambler {
  border-color: #2c604d;
  background: #0f1b17;
  color: #a9f0d0;
}

.category-cell {
  width: 270px;
  min-width: 250px;
}

.category-editor {
  display: grid;
  gap: 7px;
}

.category-choice {
  --category-color: #8794a5;
  --category-bg: rgba(135, 148, 165, 0.1);
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--category-color) 55%, var(--line));
  border-radius: var(--radius);
  background: var(--category-bg);
  transition: border-color 150ms ease, background 150ms ease;
}

.category-icon {
  display: grid;
  place-items: center;
  align-self: stretch;
  background: color-mix(in srgb, var(--category-color) 17%, transparent);
  color: var(--category-color);
  font-size: 14px;
  font-weight: 900;
}

.category-select {
  min-height: 38px;
  border: 0;
  border-radius: 0;
  padding-left: 10px;
  background: transparent;
  color: #f3f6fa;
  color-scheme: dark;
  font-size: 13px;
  font-weight: 730;
  box-shadow: none;
}

.category-select option {
  background: #151b23;
  color: #f3f6fa;
  font-weight: 650;
}

.category-select option:checked {
  background: #2b6da8;
  color: #ffffff;
}

.category-select:focus {
  background: transparent;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--category-color) 60%, transparent);
}

.category-choice[data-category="steam"] { --category-color: #75b6f2; --category-bg: rgba(58, 119, 178, 0.13); }
.category-choice[data-category="valorant"] { --category-color: #ff758a; --category-bg: rgba(255, 70, 98, 0.12); }
.category-choice[data-category="genshin"] { --category-color: #c7a8ff; --category-bg: rgba(151, 113, 224, 0.13); }
.category-choice[data-category="fortnite"] { --category-color: #7dd3fc; --category-bg: rgba(56, 189, 248, 0.12); }
.category-choice[data-category="supercell"] { --category-color: #ffd166; --category-bg: rgba(255, 193, 7, 0.11); }
.category-choice[data-category="direct"] { --category-color: #65e6b3; --category-bg: rgba(43, 209, 142, 0.11); }
.category-choice[data-category="lolz"] { --category-color: #9be15d; --category-bg: rgba(113, 204, 60, 0.11); }
.category-choice[data-category="other"] { --category-color: #b4becb; --category-bg: rgba(151, 163, 178, 0.1); }
.category-choice[data-category="manual"] { --category-color: #f0a8e2; --category-bg: rgba(218, 105, 193, 0.11); }

.category-manual {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.category-manual[hidden] {
  display: none;
}

.category-manual-input {
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}

.category-save {
  min-height: 36px;
  padding: 0 9px;
}

.category-status {
  min-height: 16px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-status.success { color: #8ccfb3; }
.category-status.warning { color: #ffe0a0; }
.category-status.error { color: #ffb0b0; }

tbody tr {
  background: #11151b;
}

tbody tr:hover {
  background: #151b23;
}

tr:last-child td {
  border-bottom: 0;
}

.empty {
  padding: 26px 18px;
  color: var(--muted);
  text-align: center;
}

.preview-panel {
  display: grid;
  width: min(1120px, calc(100vw - 32px));
  max-height: calc(100vh - 56px);
  min-height: min(720px, calc(100vh - 56px));
  padding: 0;
  overflow: hidden;
  transform: translateY(18px) scale(0.98);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}

.modal-overlay.open .preview-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-open {
  overflow: hidden;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background: rgba(5, 7, 10, 0.74);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-left: auto;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 680;
  white-space: nowrap;
}

.toggle-control input {
  width: 17px;
  min-width: 17px;
  height: 17px;
  min-height: 17px;
  margin: 0;
  accent-color: var(--accent);
}

.modal-head .status-pill {
  margin-top: 8px;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--line);
  padding: 0;
  background: #111820;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  border-color: #354353;
  background: #202936;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: #111820;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 760;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1.45fr 1.2fr 0.8fr;
  gap: 14px;
  margin: 0;
  padding: 14px 18px 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.meta-grid div {
  min-width: 0;
}

dt {
  margin-bottom: 4px;
  font-size: 12px;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 680;
}

.iframe-shell {
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #fff;
}

iframe {
  display: block;
  width: 100%;
  height: min(620px, calc(100vh - 260px));
  min-height: 360px;
  border: 0;
  background: #fff;
}

.preview-loader {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 18px;
  color: var(--muted-strong);
  font-weight: 680;
}

.preview-loader[hidden] {
  display: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.message {
  border: 1px solid rgba(68, 209, 155, 0.22);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--success-bg);
  color: #a9f0d0;
}

.message.error {
  border-color: rgba(255, 107, 107, 0.22);
  background: var(--danger-bg);
  color: #ffb0b0;
}

.message.warning {
  margin: 0 0 14px;
  border-color: rgba(247, 199, 107, 0.22);
  background: var(--warning-bg);
  color: #ffe0a0;
}

.preview-panel > .message {
  margin: 14px 18px;
}

@media (max-width: 840px) {
  .topbar,
  .layout {
    width: min(100% - 28px, 1500px);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-top: 22px;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .add-panel,
  .add-form,
  .import-form,
  .table-controls,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-head button,
  .add-form button,
  .import-actions button,
  .topbar button,
  .topbar-actions button {
    width: 100%;
  }

  .table-wrap {
    max-height: 560px;
    min-height: 420px;
  }

  table {
    min-width: 1260px;
  }

  iframe {
    height: min(560px, calc(100vh - 300px));
    min-height: 340px;
  }
}

@media (max-width: 520px) {
  .auth-page {
    padding: 14px;
  }

  .login-panel,
  .panel {
    padding: 15px;
  }

  .table-wrap {
    margin: 0 -15px;
    max-height: 520px;
    min-height: 380px;
  }

  th,
  td {
    padding: 12px 14px;
  }

  button.compact {
    min-height: 36px;
  }

  .preview-panel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    min-height: calc(100vh - 20px);
  }

  iframe {
    height: calc(100vh - 320px);
    min-height: 300px;
  }
}
