:root {
  /* ------------------------------------------------------------------
     Atlas Visual Language — single source of truth.
     Dark-Atlas is the dominant theme; light tokens redefine the same
     semantic names in the light @media block. Components consume only
     the semantic --bg/--fg/--accent/--err etc. — never the raw hex.
     If you tune tokens, tune all four CSS files in the same diff.
     ------------------------------------------------------------------ */
  --atlas-petrol:    #153937;
  --atlas-petrol-2:  #102b29;
  --atlas-teal:      #1F4E4A;
  --atlas-teal-2:    #29605B;
  --atlas-ochre:     #E6A24A;
  --atlas-ochre-2:   #C7873A;
  --atlas-sand:      #F2D6A2;
  --atlas-sand-mute: #C9B385;
  --atlas-sage:      #7FA39A;
  --atlas-sage-2:    #6A8C84;
  --atlas-coral:     #D97A5B;
  --atlas-terracotta:#A63D2F;
  --atlas-burnt:     #C65A2E;
  --atlas-clay:      #8C4A2F;

  --atlas-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");

  --bg:           var(--atlas-petrol-2);
  --bg-elev:      var(--atlas-petrol);
  --bg-raised:   var(--atlas-teal);
  --bg-input:    var(--atlas-teal);
  --fg:          var(--atlas-sand);
  --fg-muted:    var(--atlas-sand-mute);
  --accent:      var(--atlas-ochre);
  --accent-hov:  var(--atlas-ochre-2);
  --accent-fade: rgba(230, 162, 74, 0.18);
  --user-bg:     var(--atlas-teal-2);
  --oji-bg:      rgba(31, 78, 74, 0.55);
  --border:      rgba(242, 214, 162, 0.10);
  --border-strong: rgba(242, 214, 162, 0.22);
  --warning:     var(--atlas-coral);
  --error:       var(--atlas-terracotta);
  --error-fg:    #F4C9B8;
  --at-cap:      var(--atlas-burnt);
  --focus-ring:  var(--atlas-ochre);

  --secondary:     var(--atlas-sage);
  --secondary-hov: var(--atlas-sage-2);
  --branch-glow:   rgba(230, 162, 74, 0.30);

  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", sans-serif;
  --font-headline: ui-serif, "Playfair Display", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 22px;

  --shadow-1: 0 1px 0 rgba(0, 0, 0, 0.25);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:           #F6EFE2;
    --bg-elev:      #FBF6EC;
    --bg-raised:    #F2D6A2;
    --bg-input:    #FEFCF8;
    --fg:          #153937;
    --fg-muted:    #4A6E69;
    --accent:      #C7873A;
    --accent-hov:  #A86A26;
    --accent-fade: rgba(199, 135, 58, 0.16);
    --user-bg:     #F2D6A2;
    --oji-bg:      #FBF6EC;
    --border:      rgba(21, 57, 55, 0.12);
    --border-strong: rgba(21, 57, 55, 0.25);
    --error-fg:    #6B1C12;
    --secondary:     #7FA39A;
    --secondary-hov: #6A8C84;
    --branch-glow:   rgba(230, 162, 74, 0.22);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--atlas-grain);
  background-size: 160px 160px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
}

body { display: flex; flex-direction: column; }

header { position: relative; z-index: 10; }
main   { position: relative; z-index: 1; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  min-height: 56px;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-name {
  font-family: var(--font-headline);
  font-weight: 600;
  letter-spacing: 0.01em;
  font-size: 1.15rem;
  color: var(--fg);
}
.brand-sep { color: var(--fg-muted); }
.brand-sub {
  font-family: var(--font-headline);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--fg-muted);
  letter-spacing: 0.02em;
}
.dot {
  width: 12px;
  height: 12px;
  background: var(--accent);
  display: inline-block;
  clip-path: polygon(50% 0%, 65% 35%, 100% 50%, 65% 65%, 50% 100%, 35% 65%, 0% 50%, 35% 35%);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.surface-nav {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-wrap: wrap;
}
.surface-link {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color 120ms ease, background-color 120ms ease;
}
.surface-link:hover { color: var(--fg); background: var(--accent-fade); }
.surface-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.surface-link.is-current {
  color: var(--fg);
  background: var(--accent-fade);
  font-weight: 600;
}

.account-wrap { position: relative; }
.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.25rem 0.6rem 0.25rem 0.3rem;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 240px;
  min-height: 36px;
}
.account-chip:hover { border-color: var(--accent); }
.account-chip:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.account-chip .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--atlas-ochre);
  color: var(--atlas-petrol);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.account-chip .email-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-muted);
}
.account-chip .caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--fg-muted);
  margin-right: 2px;
}
.account-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  min-width: 220px;
  padding: 0.4rem;
  z-index: 20;
}
.account-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--fg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 36px;
}
.account-menu button:hover { background: var(--accent-fade); }
.account-menu button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.account-menu .menu-section {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.account-menu hr { border: none; border-top: 1px solid var(--border); margin: 0.3rem 0; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.signin-wrap { margin: auto; text-align: center; padding: 2rem 1.25rem; max-width: 460px; width: 100%; }
.signin-medallion { width: 88px; height: 88px; margin: 0 auto 1.5rem; color: var(--accent); filter: drop-shadow(0 1px 0 rgba(0,0,0,0.2)); }
.signin-headline { font-family: var(--font-headline); font-size: 1.75rem; color: var(--fg); margin: 0 0 0.5rem; letter-spacing: 0.005em; }
.signin-prose { color: var(--fg-muted); margin: 0 0 1.75rem; font-size: 0.95rem; }
.signin-prose strong { color: var(--fg); font-weight: 600; }
.signin-error {
  margin-top: 1.25rem;
  color: var(--error-fg);
  background: rgba(166, 61, 47, 0.18);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
}

.access-denied { margin: auto; text-align: center; padding: 2.5rem 1.5rem; max-width: 460px; }
.access-denied .medallion { width: 72px; height: 72px; margin: 0 auto 1.25rem; color: var(--at-cap); }
.access-denied h2 { font-family: var(--font-headline); color: var(--fg); margin: 0 0 0.5rem; font-size: 1.4rem; }
.access-denied p { color: var(--fg-muted); margin: 0 0 1.5rem; }
.access-denied .email-shown { color: var(--fg); font-family: var(--font-mono); font-size: 0.9rem; }
.access-denied button {
  background: var(--accent);
  color: var(--atlas-petrol);
  border: none;
  border-radius: var(--radius-md);
  padding: 0.65rem 1.2rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.access-denied button:hover { background: var(--accent-hov); }
.access-denied button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.settings-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
  opacity: 1;
}
.settings-wrap.fade-in { animation: oji-fade-in 220ms ease both; }
@keyframes oji-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

.settings-head {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}
.section-title {
  font-family: var(--font-headline);
  font-size: 1.35rem;
  color: var(--fg);
  margin: 0 0 0.35rem;
  letter-spacing: 0.005em;
}
.settings-lead {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.92rem;
  max-width: 52ch;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 640px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.15rem; }
  .settings-card.is-server { grid-column: 1 / -1; }
}

.settings-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-shadow: var(--shadow-1);
}
.settings-card.is-stubbed { opacity: 0.92; }
.settings-card-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.settings-card-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: var(--accent);
  clip-path: polygon(50% 0%, 65% 35%, 100% 50%, 65% 65%, 50% 100%, 35% 65%, 0% 50%, 35% 35%);
}
.settings-card-icon.is-warmth { background: var(--atlas-coral); border-radius: 50%; clip-path: none; }
.settings-card-icon.is-tone { background: var(--secondary); clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); }
.settings-card-icon.is-motion { background: var(--atlas-teal-2); border-radius: 4px; clip-path: none; transform: rotate(45deg); }
.settings-card-icon.is-server { background: var(--atlas-petrol); clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 50% 100%, 0% 75%); }

.settings-card-title {
  font-family: var(--font-headline);
  font-size: 1.05rem;
  margin: 0;
  color: var(--fg);
  font-weight: 600;
}
.settings-card-desc {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}
.settings-stub-note {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--secondary);
}

.settings-readonly {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--fg);
  word-break: break-all;
}

.settings-control {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--fg-muted);
  font-size: 0.88rem;
}
.settings-control-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.settings-control input[type="range"],
.settings-control select {
  width: 100%;
  min-height: 40px;
  background: var(--bg-input);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  font-family: inherit;
  font-size: 0.9rem;
}
.settings-control input[type="range"] { padding: 0; }
.settings-control input:disabled,
.settings-control select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}
.settings-check {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
}
.settings-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.settings-server-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.settings-server-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--bg-raised);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
}
.settings-server-label { color: var(--fg); font-size: 0.9rem; }
.settings-server-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  background: var(--oji-bg);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  .settings-wrap.fade-in { animation: none; }
}

@media (max-width: 480px) {
  header {
    padding: 0.6rem 0.85rem;
    padding-top: calc(0.6rem + env(safe-area-inset-top, 0px));
  }
  .brand-name { font-size: 1.05rem; }
  .brand-sub { font-size: 0.85rem; }
  .account-chip { max-width: 120px; }
  .account-chip .email-text { font-size: 0.8rem; }
  .surface-link { font-size: 0.78rem; padding: 0.25rem 0.4rem; }
  .settings-wrap { padding: 0.85rem 0.65rem 1.5rem; }
  .section-title { font-size: 1.15rem; }
  .signin-headline { font-size: 1.4rem; }
}