:root {
  color-scheme: light;
  --paper: #faf7f2;
  --surface: #ffffff;
  --ink: #242a27;
  --muted: #68736d;
  --line: #d9ded8;
  --gold: #c4956a;
  --gold-dark: #82562f;
  --leaf: #416f5f;
  --leaf-dark: #1d2924;
  --red: #a94941;
  --blue: #28546b;
  --focus: #1678b8;
  --max: 1120px;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Noto Sans Thai", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(22, 120, 184, 0.3);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.topbar {
  min-height: 72px;
  padding: 10px max(20px, calc((100vw - var(--max)) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: #f9f5ee;
  background: var(--leaf-dark);
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}
.brand img { width: 42px; height: 42px; object-fit: contain; }
.brand > span { font-size: 20px; font-weight: 850; }
.brand small {
  padding: 3px 6px;
  color: #fff;
  background: var(--red);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 850;
}
.top-actions { display: flex; align-items: center; gap: 16px; }
.service-state { display: inline-flex; align-items: center; gap: 7px; color: #cbd8d2; font-size: 12px; }
.service-state i { width: 8px; height: 8px; border-radius: 50%; background: #a8a8a8; }
.service-state i.online { background: #59c887; box-shadow: 0 0 0 4px rgba(89,200,135,0.16); }
.language-switch { display: inline-flex; border: 1px solid rgba(255,255,255,0.25); border-radius: 6px; overflow: hidden; }
.language-switch button {
  width: 42px;
  height: 34px;
  border: 0;
  color: #d9e2de;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}
.language-switch button.active { color: var(--leaf-dark); background: #fff; }

.app-shell {
  width: min(var(--max), calc(100% - 40px));
  min-height: calc(100vh - 112px);
  margin: 40px auto;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 16px 40px rgba(30, 42, 36, 0.08);
}
.access-workspace { padding: 54px 58px; min-width: 0; }
.workspace-head { max-width: 640px; }
.kicker { margin: 0 0 14px; color: var(--leaf); font-size: 12px; font-weight: 900; }
.workspace-head h1 { margin: 0; font-size: 42px; line-height: 1.12; }
.workspace-head > p:last-child { margin: 14px 0 0; color: var(--muted); font-size: 16px; }
.auth-flow { margin-top: 42px; max-width: 640px; }
.flow-step label, .rotate-form label { display: block; margin-bottom: 9px; font-size: 13px; font-weight: 800; }
.input-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
input {
  min-width: 0;
  height: 52px;
  padding: 0 15px;
  border: 1px solid #bfc8c1;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}
input:hover { border-color: #8f9c94; }
.primary, .secondary, .quiet-button, .copy-button, .danger-button, .back-button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 820;
}
.primary { border: 1px solid var(--leaf); color: #fff; background: var(--leaf); }
.primary:hover { background: #315b4d; }
.primary:disabled { cursor: wait; opacity: 0.55; }
.secondary { border: 1px solid #aeb8b1; color: var(--ink); background: #fff; }
.secondary:hover { border-color: var(--leaf); color: var(--leaf); }
.full { width: 100%; margin-top: 22px; }
.back-button { min-height: 32px; margin: 0 0 18px; padding: 0; border: 0; color: var(--leaf); background: transparent; }
.field-note { margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.form-status { min-height: 24px; margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.form-status.error { color: var(--red); }
.form-status.success { color: var(--leaf); }

.key-reveal, .dashboard {
  padding-top: 4px;
  border-top: 3px solid var(--gold);
}
.key-reveal h2, .dashboard h2 { margin: 6px 0 6px; font-size: 28px; }
.key-reveal > p:not(.success-label):not(.field-note) { margin: 0 0 20px; color: var(--muted); }
.success-label { margin: 18px 0 0; color: var(--leaf); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.secret-row, .endpoint-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.secret-row input { font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; }
.copy-button { border: 1px solid #aeb8b1; color: var(--ink); background: #fff; }
.copy-button:hover { border-color: var(--gold-dark); color: var(--gold-dark); }
.key-reveal h3 { margin: 26px 0 10px; font-size: 14px; }
.word-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.word-row span {
  padding: 12px 8px;
  border: 1px solid #e0d4c8;
  border-radius: 6px;
  color: var(--gold-dark);
  background: #fff9f1;
  text-align: center;
  font-family: "Cascadia Code", Consolas, monospace;
  font-weight: 800;
}
.inline-copy { min-height: 36px; margin-top: 8px; padding: 0 12px; font-size: 12px; }
.dashboard-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.quiet-button { border: 0; color: var(--muted); background: transparent; }
.usage-line { margin-top: 25px; display: flex; align-items: baseline; justify-content: space-between; gap: 20px; }
.usage-line strong { font-size: 24px; }
.usage-line span { color: var(--muted); font-size: 12px; }
.usage-track { height: 8px; margin-top: 10px; overflow: hidden; border-radius: 4px; background: #e8ece8; }
.usage-track span { display: block; width: 0; height: 100%; background: var(--leaf); transition: width 220ms ease; }
.account-facts { margin: 25px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.account-facts div { min-width: 0; padding: 14px; background: #fff; }
.account-facts dt { color: var(--muted); font-size: 11px; }
.account-facts dd { margin: 5px 0 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 800; }
.rotate-form { margin-top: 20px; padding: 18px; border-left: 3px solid var(--red); background: #fff7f5; }
.rotate-form input { width: 100%; }
.danger-button { width: 100%; margin-top: 10px; border: 1px solid var(--red); color: #fff; background: var(--red); }

.service-pane {
  min-width: 0;
  padding: 48px 38px;
  color: #f7f2ea;
  background: var(--leaf-dark);
}
.mark-stage { width: 220px; height: 220px; margin: 0 auto 34px; }
.mark-stage img { width: 100%; height: 100%; object-fit: contain; }
.service-overline { margin: 0 0 8px; color: #b9c8c1; font-size: 11px; font-weight: 850; text-transform: uppercase; }
.endpoint-row code { min-width: 0; padding: 13px; overflow: hidden; border: 1px solid rgba(255,255,255,0.18); border-radius: 6px; color: #fff; background: rgba(255,255,255,0.06); text-overflow: ellipsis; white-space: nowrap; }
.copy-button.dark { border-color: rgba(255,255,255,0.25); color: #fff; background: rgba(255,255,255,0.06); }
.service-facts { margin-top: 34px; border-top: 1px solid rgba(255,255,255,0.15); }
.service-facts div { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid rgba(255,255,255,0.15); }
.service-facts span { color: #b9c8c1; font-size: 12px; }
.service-facts strong { font-size: 14px; }
.privacy-line { margin: 30px 0 0; color: #a9b9b1; font-size: 12px; }

.cookie-gate {
  position: fixed;
  right: 20px;
  bottom: 20px;
  left: 20px;
  z-index: 50;
  width: min(680px, calc(100% - 40px));
  margin: 0 auto;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border: 1px solid #bfc8c1;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 36px rgba(20, 30, 25, 0.18);
}
.cookie-gate img { width: 42px; height: 42px; object-fit: contain; }
.cookie-gate strong { display: block; font-size: 13px; }
.cookie-gate p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

@media (max-width: 820px) {
  .service-state { display: none; }
  .app-shell { width: 100%; margin: 0; grid-template-columns: 1fr; border: 0; box-shadow: none; }
  .access-workspace { padding: 38px 22px 46px; }
  .workspace-head h1 { font-size: 34px; }
  .auth-flow { margin-top: 32px; }
  .service-pane { padding: 36px 22px 44px; }
  .mark-stage { width: 160px; height: 160px; }
}

@media (max-width: 540px) {
  .topbar { min-height: 64px; padding: 8px 14px; }
  .brand img { width: 38px; height: 38px; }
  .input-action, .secret-row { grid-template-columns: 1fr; }
  .input-action button, .secret-row button { width: 100%; min-height: 48px; }
  .word-row, .account-facts { grid-template-columns: 1fr; }
  .word-row { gap: 6px; }
  .usage-line { align-items: flex-start; flex-direction: column; gap: 2px; }
  .cookie-gate { grid-template-columns: auto 1fr; }
  .cookie-gate .primary { grid-column: 1 / -1; width: 100%; }
}

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