:root,
[data-theme="light"] {
  color-scheme: light;
  --bg-base: #eef0f4;
  --bg-surface: #ffffff;
  --bg-elevated: #f7f8fb;
  --text-primary: #14171f;
  --text-muted: #616a7d;
  --border: rgba(20, 23, 31, 0.10);
  --border-strong: rgba(20, 23, 31, 0.16);
  --accent: #2f6bff;
  --accent-hover: #1f57e6;
  --accent-soft: rgba(47, 107, 255, 0.10);
  --gold: #b8873c;
  --gold-soft: rgba(184, 135, 60, 0.14);
  --message-ok-bg: #ecfdf3;
  --message-ok-border: #86efac;
  --message-ok-text: #166534;
  --message-error-bg: #fef2f2;
  --message-error-border: #fca5a5;
  --message-error-text: #991b1b;
  --danger: #c0392b;
  --backdrop: rgba(15, 17, 23, 0.45);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, 0.14);
  --shadow-modal: 0 24px 70px rgba(16, 24, 40, 0.22);
  --input-bg: #ffffff;
  --code-bg: #f1f3f7;
  --captcha-accent: #2f6bff;
  --radius: 14px;
  --radius-sm: 10px;
  --glow: radial-gradient(1200px 600px at 50% -10%, rgba(47, 107, 255, 0.06), transparent 60%);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-base: #0a0c11;
  --bg-surface: #141822;
  --bg-elevated: #1b202c;
  --text-primary: #eaedf4;
  --text-muted: #98a1b5;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --accent: #5b8cff;
  --accent-hover: #7aa2ff;
  --accent-soft: rgba(91, 140, 255, 0.16);
  --gold: #d9b46a;
  --gold-soft: rgba(217, 180, 106, 0.14);
  --message-ok-bg: #17281f;
  --message-ok-border: #2d6a4f;
  --message-ok-text: #b7f0d3;
  --message-error-bg: #2c1719;
  --message-error-border: #6a2d2d;
  --message-error-text: #f0b7b7;
  --danger: #ff6b6b;
  --backdrop: rgba(4, 6, 10, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 30px 70px rgba(0, 0, 0, 0.5);
  --shadow-modal: 0 30px 80px rgba(0, 0, 0, 0.6);
  --input-bg: #10141d;
  --code-bg: #0c0f16;
  --captcha-accent: #7aa2ff;
  --radius: 14px;
  --radius-sm: 10px;
  --glow: radial-gradient(1200px 620px at 50% -12%, rgba(91, 140, 255, 0.10), transparent 62%);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text-primary);
  background-color: var(--bg-base);
  /* Layered premium backdrop: soft accent glow + faint hex circuit texture. */
  background-image: var(--glow),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='96' viewBox='0 0 56 96'%3E%3Cpath fill='none' stroke='%23808aa0' stroke-opacity='0.05' stroke-width='1' d='M28 0l24 14v28L28 56 4 42V14zM28 56l24 14v28M28 56L4 70v28'/%3E%3C/svg%3E");
  background-attachment: fixed, fixed;
  background-position: center top, center;
  background-repeat: no-repeat, repeat;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open {
  overflow: hidden;
}

.site-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.site-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.control-select,
.theme-toggle {
  width: auto;
  min-height: 40px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.control-select:hover,
.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-toggle {
  margin-left: auto;
  font-weight: 600;
}

.shell {
  max-width: 880px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 28px) 64px;
}

.hero {
  text-align: center;
  margin-bottom: 32px;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(1.9rem, 5vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.hero h1::after {
  content: "";
  display: block;
  width: 56px;
  height: 3px;
  margin: 14px auto 0;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.02rem;
}

.card {
  position: relative;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg-surface) 100%, transparent), var(--bg-surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 28px);
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 16px;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.plan {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: var(--bg-elevated);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.plan-price {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 8px 0;
  letter-spacing: -0.01em;
}

.plan-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.beta-banner {
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--gold-soft);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.55;
}

.plan-selectable {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.plan-selectable:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.plan-selectable.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-sm);
}

.subscribe-section {
  margin: 20px 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  display: grid;
  gap: 14px;
}

.subscribe-section h3 {
  margin: 0;
  font-size: 1.1rem;
}

.beta-notice {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.subscribe-devices-field input {
  width: 100%;
  max-width: 160px;
  margin-top: 6px;
}

.subscribe-devices-hint {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.subscribe-message {
  margin: 0;
  font-size: 0.92rem;
}

.subscribe-message.error {
  color: var(--danger);
}

.auth-hint {
  margin: 0 0 20px;
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.auth-action-btn {
  margin: 0;
  width: auto;
  flex: 1 1 180px;
  padding: 14px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: inherit;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 0.95rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.auth-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.auth-action-btn.primary,
.auth-action-btn#open-login {
  background: linear-gradient(180deg, var(--accent), var(--accent-hover));
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 6px 18px var(--accent-soft);
}

/* Account dashboard — organised into panels */
#dashboard {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#dashboard .card {
  margin-bottom: 0;
}

.account-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.account-id {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#user-email {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#user-nickname {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

#subscription-info {
  margin: 16px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  font-size: 0.95rem;
}

#subscription-info:empty {
  display: none;
}

.account-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.account-panel-head h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.account-panel-badge {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.account-panel-badge:empty {
  display: none;
}

.account-panel-hint {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Panels are full cards now — cancel the old section dividers/spacing. */
#dashboard .devices-section,
#dashboard .storage-section,
#dashboard .logs-section,
#dashboard .subscribe-section {
  margin: 0;
  padding: clamp(18px, 3vw, 26px);
  padding-top: clamp(18px, 3vw, 26px);
  border-top: none;
  background: var(--bg-surface);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: clamp(20px, 4vw, 28px);
  box-shadow: var(--shadow-modal);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-close {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.modal-close:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.auth-message {
  margin: 0 0 14px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--message-ok-bg);
  border: 1px solid var(--message-ok-border);
  color: var(--message-ok-text);
  font-size: 0.92rem;
}

.auth-message.error {
  background: var(--message-error-bg);
  border-color: var(--message-error-border);
  color: var(--message-error-text);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--text-muted);
}

input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  color: inherit;
  box-sizing: border-box;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Buttons: sized to content by default — no full-width stretching. */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  min-height: 44px;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: inherit;
  cursor: pointer;
  box-sizing: border-box;
  font: inherit;
  font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

button:active {
  transform: translateY(0);
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions button {
  margin: 0;
  flex: 1;
}

.primary-btn,
button[type="submit"],
#gen-code,
#logout {
  cursor: pointer;
  background: linear-gradient(180deg, var(--accent), var(--accent-hover));
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 6px 18px var(--accent-soft);
}

.primary-btn:hover,
button[type="submit"]:hover,
#gen-code:hover,
#logout:hover,
.auth-action-btn.primary:hover {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent-hover));
  border-color: transparent;
}

.secondary-btn {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  cursor: pointer;
}

/* Anchor styled as a button (e.g. log download links). */
a.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}

a.secondary-btn:hover {
  border-color: var(--accent);
}

.captcha-field .secondary-btn {
  margin-top: 8px;
}

/* Dashboard standalone actions sit inline, not stretched. */
#gen-code,
#logout {
  margin-top: 16px;
  margin-right: 10px;
}

#logout {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-muted);
  box-shadow: none;
}

#logout:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

pre {
  background: var(--code-bg);
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow: auto;
  border: 1px solid var(--border);
  font-size: 0.88rem;
}

#activation-code:empty {
  display: none;
}

/* Sections: devices / storage / logs */
.devices-section,
.storage-section,
.logs-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.devices-section h3,
.storage-section h3,
.logs-section h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 650;
}

.devices-summary,
.devices-empty,
.storage-hint,
.storage-empty,
.logs-hint,
.logs-empty {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.storage-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin: 6px 0 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
  font-weight: 550;
}

.storage-toggle input {
  width: 20px;
  height: 20px;
  min-height: 0;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex: 0 0 auto;
}

.devices-table,
.storage-table,
.logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.devices-table th,
.devices-table td,
.storage-table th,
.storage-table td,
.logs-table th,
.logs-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.devices-table th,
.storage-table th,
.logs-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.devices-meta {
  margin-top: 4px;
  font-size: 0.76rem;
  color: var(--text-muted);
  word-break: break-all;
}

.devices-actions {
  width: 1%;
  white-space: nowrap;
}

.devices-actions .secondary-btn,
.logs-table .secondary-btn {
  min-height: 36px;
  padding: 7px 14px;
  font-size: 0.85rem;
}

code {
  font-size: 0.82rem;
  word-break: break-all;
  color: var(--text-muted);
}

/* Responsive — ~half of users are on phones. */
@media (max-width: 640px) {
  .shell {
    padding: 20px 14px 48px;
  }

  .hero h1 {
    font-size: 1.7rem;
  }

  .auth-actions {
    flex-direction: column;
  }

  .auth-action-btn {
    flex: 1 1 auto;
  }

  .modal-actions {
    flex-direction: column;
  }

  /* Tables scroll horizontally instead of squashing. */
  .devices-list,
  .storage-backups-list,
  #logs-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .devices-table,
  .storage-table,
  .logs-table {
    min-width: 460px;
  }

  #gen-code,
  #logout {
    width: 100%;
    margin-right: 0;
  }
}
