:root {
  color: #24251f;
  background: #f8f3ea;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --ink: #24251f;
  --muted: #77756b;
  --paper: #fffdf8;
  --line: rgba(62, 58, 48, 0.12);
  --terracotta: #eeb18d;
  --terracotta-ink: #974416;
  --moss: #c8ccb1;
  --moss-ink: #465a36;
  --blue: #bfd3e4;
  --blue-ink: #345d7e;
  --stone: #e9ded0;
  --shadow: 0 18px 45px rgba(67, 56, 39, 0.09);
  --system-font: "Segoe UI Variable", "Avenir Next", Inter, ui-sans-serif, system-ui, sans-serif;
  --system-ink: #17233e;
  --system-muted: #626b7d;
  --system-primary: #3157c8;
  --system-primary-strong: #2444a8;
  --system-soft: #e8edff;
  --system-line: rgba(23, 35, 62, 0.13);
  --system-shadow: 0 18px 45px rgba(32, 49, 91, 0.11);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.85), transparent 34rem),
    #f8f3ea;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

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

.eyebrow {
  margin: 0 0 0.4rem;
  color: #6d735e;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }

.login-page {
  display: grid;
  place-items: center;
  padding: 1.25rem;
  color: var(--system-ink);
  background:
    radial-gradient(circle at 18% 0%, rgba(232, 237, 255, 0.95), transparent 30rem),
    radial-gradient(circle at 92% 100%, rgba(238, 177, 141, 0.16), transparent 27rem),
    #f8f3ea;
  font-family: var(--system-font);
}

.login-shell {
  width: min(100%, 31rem);
  padding: clamp(1.6rem, 7vw, 3.5rem);
  border: 1px solid var(--system-line);
  border-radius: 1.6rem;
  background: rgba(255, 255, 255, 0.91);
  box-shadow: var(--system-shadow);
}

.login-mark {
  display: grid;
  width: 4rem;
  height: 4rem;
  margin-bottom: 2rem;
  place-items: center;
  border-radius: 1.05rem;
  color: white;
  background: linear-gradient(145deg, #4169df, var(--system-primary-strong));
  box-shadow: 0 12px 25px rgba(49, 87, 200, 0.22);
}

.login-mark svg { width: 2.2rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.3; }
.login-shell .eyebrow { color: var(--system-primary-strong); font-family: var(--system-font); font-weight: 700; letter-spacing: 0.11em; }
.login-shell h1 { margin-bottom: 0.8rem; font-family: var(--system-font); font-size: clamp(2.45rem, 11vw, 3.6rem); font-weight: 650; line-height: 0.98; letter-spacing: -0.05em; }
.login-intro { color: var(--system-muted); font-size: 1rem; line-height: 1.65; }
.login-form { margin-top: 2rem; }
.login-form label { display: block; margin-bottom: 0.55rem; color: var(--system-ink); font-size: 0.82rem; font-weight: 700; }
.login-field-row { display: grid; gap: 0.65rem; }

.login-form input,
.chat-composer input {
  min-width: 0;
  border: 1px solid rgba(68, 63, 52, 0.17);
  outline: none;
  color: var(--ink);
  background: #fff;
}

.login-form input { min-height: 3.4rem; padding: 0 1rem; border-color: var(--system-line); border-radius: 0.9rem; color: var(--system-ink); }
.login-form .login-code-input { font-size: 1.25rem; font-weight: 750; letter-spacing: 0.22em; text-align: center; }
.login-form input:focus { border-color: var(--system-primary); box-shadow: 0 0 0 4px rgba(49, 87, 200, 0.12); }

.login-form button {
  min-height: 3.4rem;
  padding: 0 1.2rem;
  border: 0;
  border-radius: 0.9rem;
  color: white;
  background: var(--system-primary);
  font-weight: 700;
  cursor: pointer;
}

.login-form button:hover { background: var(--system-primary-strong); }
.login-form button:disabled { opacity: 0.6; cursor: wait; }
.login-step-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; margin-top: 0.9rem; }
.login-step-actions .text-button { padding: 0.35rem 0; color: var(--system-primary-strong); font-size: 0.78rem; font-weight: 650; }
.login-step-actions .text-button:disabled { opacity: 0.55; cursor: wait; }
.status-message { min-height: 3rem; padding-top: 1rem; color: var(--system-primary-strong); font-weight: 650; line-height: 1.45; }
.privacy-note { margin: 1.5rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.78rem; line-height: 1.5; }
.mini-lock { margin-right: 0.35rem; color: #637552; font-size: 0.62rem; }
.login-page .privacy-note { border-color: var(--system-line); color: var(--system-muted); }
.login-page .mini-lock { color: var(--system-primary); }

.home-page { padding-bottom: 7.5rem; }
.home-shell { width: min(100%, 58rem); margin: 0 auto; padding: 1.4rem 1rem 3rem; }

.home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.home-header h1 { margin: 0; font-size: clamp(2rem, 8vw, 3.4rem); line-height: 1; letter-spacing: -0.035em; }
.header-actions { display: flex; align-items: flex-end; flex-direction: column; gap: 0.45rem; }
.private-pill { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.65rem 0.8rem; border-radius: 999px; color: #465a36; background: rgba(200, 204, 177, 0.52); font-size: 0.75rem; font-weight: 800; white-space: nowrap; }
.text-button { padding: 0.2rem 0.4rem; border: 0; color: var(--muted); background: transparent; font-size: 0.72rem; cursor: pointer; }
.header-actions .text-button { text-decoration: none; }
.text-button:hover { color: var(--ink); }

.settings-page {
  padding: 1.25rem;
  color: var(--system-ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(232, 237, 255, 0.82), transparent 31rem),
    #f8f3ea;
  font-family: var(--system-font);
}
.settings-shell { width: min(100%, 39rem); margin: 0 auto; padding: clamp(1rem, 5vw, 3rem) 0; }
.settings-shell h1,
.settings-shell h2 {
  font-family: var(--system-font);
  font-weight: 650;
  letter-spacing: -0.045em;
}
.settings-shell h1 { margin-bottom: 0.75rem; font-size: clamp(2.35rem, 10vw, 3.65rem); line-height: 1.02; }
.settings-shell .eyebrow { color: #53617d; font-family: var(--system-font); font-weight: 700; letter-spacing: 0.11em; }
.settings-intro { max-width: 37rem; color: var(--system-muted); line-height: 1.65; }
.back-link { display: inline-block; margin-bottom: 2rem; color: var(--system-primary-strong); font-size: 0.85rem; font-weight: 650; text-decoration: none; }
.connection-card { margin-top: 2rem; padding: clamp(1.25rem, 5vw, 2rem); border: 1px solid var(--system-line); border-radius: 1.7rem; background: rgba(255, 254, 251, 0.94); box-shadow: var(--system-shadow); }
.connection-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.connection-heading h2 { margin: 0; font-size: 1.55rem; }
.connection-state { padding: 0.45rem 0.7rem; border-radius: 999px; color: var(--system-primary-strong); background: var(--system-soft); font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.connection-state[data-state="error"], .connection-state[data-state="unavailable"] { color: #7d3024; background: #f9e2dc; }
.connection-state[data-state="pending"] { color: #5d3a91; background: #eee6fa; }
.connection-message { margin: 1.4rem 0; color: var(--system-muted); line-height: 1.55; }
.account-details { display: grid; gap: 0.65rem; margin: 0 0 1.5rem; }
.account-details div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.8rem 0; border-bottom: 1px solid var(--system-line); }
.account-details dt { color: var(--system-muted); font-size: 0.78rem; font-weight: 650; }
.account-details dd { margin: 0; font-size: 0.82rem; font-weight: 650; text-align: right; }
.device-flow { padding-top: 0.25rem; }
.device-flow > p { color: var(--system-muted); line-height: 1.55; }
.device-code { display: block; margin: 1.2rem 0; padding: 1rem; border: 1px dashed rgba(49, 87, 200, 0.3); border-radius: 1rem; color: var(--system-ink); background: #f3f5ff; font-size: clamp(1.5rem, 8vw, 2.4rem); font-weight: 750; letter-spacing: 0.11em; text-align: center; }
.device-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem; }
.primary-action, .secondary-action { display: inline-flex; min-height: 3rem; align-items: center; justify-content: center; padding: 0 1rem; border-radius: 0.9rem; font-family: var(--system-font); font-size: 0.85rem; font-weight: 650; text-decoration: none; cursor: pointer; }
.primary-action { border: 0; color: white; background: var(--system-primary); }
.primary-action:hover { background: var(--system-primary-strong); }
.secondary-action { border: 1px solid var(--system-line); color: var(--system-ink); background: white; }
.primary-action:disabled, .secondary-action:disabled { opacity: 0.58; cursor: wait; }
.danger-text { color: #8a3d30; }
.waiting-note { margin: 1.25rem 0 0; font-size: 0.78rem; font-weight: 650; }
.status-dot { display: inline-block; width: 0.55rem; height: 0.55rem; margin-right: 0.45rem; border-radius: 50%; background: var(--system-primary); box-shadow: 0 0 0 0.3rem rgba(49, 87, 200, 0.12); }
.settings-page .privacy-note { border-color: var(--system-line); color: var(--system-muted); }
.settings-page .mini-lock { color: var(--system-primary); }
.model-settings { margin-top: 1rem; }
.model-settings-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: end; gap: 0.9rem; }
.model-settings-form label { display: grid; gap: 0.45rem; color: var(--system-muted); font-size: 0.78rem; font-weight: 650; }
.model-settings-form select { width: 100%; min-height: 3rem; padding: 0 2.4rem 0 0.85rem; border: 1px solid var(--system-line); border-radius: 0.9rem; outline: none; color: var(--system-ink); background: white; font: inherit; }
.model-settings-form select:focus { border-color: var(--system-primary); box-shadow: 0 0 0 4px rgba(49, 87, 200, 0.12); }
.model-settings-form .primary-action { grid-column: 1 / -1; justify-self: start; }
.settings-save-message { min-height: 1.2rem; margin: 0.8rem 0 0; color: var(--system-primary-strong); font-size: 0.78rem; font-weight: 650; }

.area-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.area-card { display: grid; min-height: 10.2rem; padding: 1rem; place-items: center; gap: 0.5rem; border: 0; border-radius: 1.7rem; box-shadow: 0 12px 25px rgba(72, 58, 39, 0.07); cursor: pointer; transition: transform 160ms ease, box-shadow 160ms ease; }
.area-card:hover { transform: translateY(-2px); box-shadow: 0 17px 32px rgba(72, 58, 39, 0.1); }
.area-card:focus-visible, .shortcut-row:focus-visible, .manual-row:focus-visible, button:focus-visible { outline: 3px solid rgba(58, 91, 119, 0.45); outline-offset: 3px; }
.area-card svg { width: 4rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.3; }
.area-card span { font-family: Georgia, "Times New Roman", serif; font-size: 1.55rem; }
.area-1 { color: var(--terracotta-ink); background: var(--terracotta); }
.area-2 { color: var(--moss-ink); background: var(--moss); }
.area-3 { color: var(--blue-ink); background: var(--blue); }
.area-4 { color: #51463b; background: var(--stone); }

.content-section { margin-top: 2.2rem; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.section-heading h2 { margin: 0; font-size: 1.65rem; }
.shortcut-list, .manual-list { display: grid; gap: 0.65rem; }

.shortcut-row,
.manual-row {
  display: flex;
  width: 100%;
  min-height: 4.9rem;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 8px 20px rgba(72, 58, 39, 0.045);
  font-size: 0.95rem;
  font-weight: 750;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.shortcut-icon { display: grid; width: 3.25rem; height: 3.25rem; flex: 0 0 auto; place-items: center; border-radius: 1rem; color: var(--terracotta-ink); background: #f7d3bd; }
.shortcut-icon svg { width: 2rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.shortcut-row:nth-child(2) .shortcut-icon { color: var(--moss-ink); background: #e4e6d7; }
.chevron { margin-left: auto; color: #7a796f; font-size: 1.7rem; font-weight: 400; }
.manual-row > span:first-child { display: grid; gap: 0.2rem; }
.manual-row small { color: var(--muted); font-size: 0.72rem; font-weight: 600; }
.empty-state { padding: 1rem; border: 1px dashed var(--line); border-radius: 1rem; color: var(--muted); }

.chat-thread { display: grid; gap: 0.8rem; margin-top: 2rem; padding: 1rem 0 7rem; scroll-margin-bottom: 8rem; font-family: var(--system-font); }
.chat-message { max-width: 90%; padding: 0.9rem 1rem; border-radius: 1.2rem; line-height: 1.55; scroll-margin-bottom: 7rem; white-space: pre-line; }
.chat-message p { margin: 0; }
.chat-message small { display: block; margin-top: 0.65rem; color: inherit; opacity: 0.65; font-size: 0.68rem; }
.chat-message.user { justify-self: end; color: white; background: var(--system-primary); border-bottom-right-radius: 0.35rem; }
.chat-message.assistant { justify-self: start; border: 1px solid var(--line); background: var(--paper); border-bottom-left-radius: 0.35rem; }
.chat-message.pending { min-width: min(16rem, 80vw); color: var(--system-muted); }
.chat-message.error { color: #7d3024; background: #f9e2dc; }
.chat-message.stopped { color: var(--system-muted); background: #f0f2f7; }
.run-activity { display: grid; gap: 0.25rem; margin: 0.65rem 0 0; padding: 0; list-style: none; font-size: 0.74rem; opacity: 0.68; }
.run-activity li:not(:last-child) { opacity: 0.55; }
.run-actions { display: flex; margin-top: 0.8rem; }
.run-action { width: auto; min-height: 2.35rem; padding: 0.45rem 0.9rem; border: 1px solid rgba(49, 87, 200, 0.24); border-radius: 999px; color: var(--system-primary-strong); background: #f2f5ff; font: 700 0.78rem/1 var(--system-font); cursor: pointer; }
.run-action:hover { border-color: var(--system-primary); background: #e8edff; }
.run-action:disabled { opacity: 0.5; cursor: wait; }
.run-action.retry { margin-top: 0.8rem; }
.source-disclosure { max-width: 100%; margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px solid var(--line); color: var(--system-muted); white-space: normal; }
.source-disclosure summary { width: fit-content; color: var(--system-primary-strong); font-size: 0.78rem; font-weight: 750; cursor: pointer; }
.source-disclosure ul { display: grid; gap: 0.45rem; margin: 0.65rem 0 0; padding-left: 1.1rem; font-size: 0.75rem; }
.source-disclosure li { overflow-wrap: anywhere; }
.source-disclosure a { color: var(--system-primary-strong); text-decoration-thickness: 0.08em; text-underline-offset: 0.16em; }
.source-disclosure a:hover { color: var(--system-primary); }

.chat-composer {
  position: fixed;
  z-index: 10;
  right: max(0.8rem, env(safe-area-inset-right));
  bottom: max(0.8rem, env(safe-area-inset-bottom));
  left: max(0.8rem, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: auto 1fr auto;
  width: min(calc(100% - 1.6rem), 54rem);
  min-height: 4.5rem;
  margin: 0 auto;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem;
  border: 1px solid rgba(49, 87, 200, 0.22);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 18px 55px rgba(32, 49, 91, 0.18);
  backdrop-filter: blur(12px);
  font-family: var(--system-font);
}

.sparkle { display: grid; width: 3.25rem; height: 3.25rem; place-items: center; border-radius: 50%; color: white; background: var(--system-primary); font-size: 1.3rem; }
.chat-composer input { width: 100%; min-height: 3.25rem; padding: 0 0.8rem; border-color: transparent; background: transparent; }
.chat-composer input:focus { box-shadow: none; }
.chat-composer button { width: 3.25rem; height: 3.25rem; border: 0; border-radius: 50%; color: white; background: var(--system-primary); font-size: 1.65rem; cursor: pointer; }
.chat-composer button:hover { background: var(--system-primary-strong); }
.chat-composer button:disabled { opacity: 0.55; cursor: wait; }

@media (min-width: 42rem) {
  .home-shell { padding: 2.5rem 2rem 4rem; }
  .area-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .area-card { min-height: 12rem; }
  .shortcut-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-field-row { grid-template-columns: 1fr auto; }
}

@media (max-width: 30rem) {
  .model-settings-form { grid-template-columns: 1fr; }
  .model-settings-form .primary-action { grid-column: auto; }
}

@media (max-width: 24rem) {
  .home-header { display: block; }
  .header-actions { margin-top: 0.8rem; align-items: flex-start; }
  .area-card { min-height: 8.8rem; }
  .area-card svg { width: 3rem; }
  .area-card span { font-size: 1.25rem; }
}

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