:root {
  color-scheme: light;
  --ink: #14202b;
  --navy: #15324a;
  --navy-2: #1d435f;
  --tamarind: #d45c2d;
  --paper: #fbfcfe;
  --surface: #ffffff;
  --mist: #edf4f7;
  --line: #d8e2e9;
  --muted: #536775;
  --danger: #a33a20;
  --success: #27734e;
  --focus: #f4a261;
  --shadow: 0 18px 60px rgba(20, 37, 50, 0.08);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, "Noto Sans SC", "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--paper); }
body { min-width: 320px; min-height: 100dvh; margin: 0; background: var(--paper); font-size: 16px; line-height: 1.55; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, dialog:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: -1000px; padding: 10px 14px; border-radius: 10px; background: var(--navy); color: white; }
.skip-link:focus { left: 8px; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }

.app-header { position: sticky; z-index: 20; top: 0; padding-top: var(--safe-top); border-bottom: 1px solid color-mix(in srgb, var(--line) 78%, transparent); background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(18px); }
.header-inner { display: flex; align-items: center; justify-content: space-between; width: min(1180px, 100%); min-height: 64px; margin: 0 auto; padding: 8px 16px; gap: 16px; }
.brand { display: inline-flex; min-height: 44px; align-items: center; gap: 9px; color: var(--navy); text-decoration: none; }
.brand-mark { display: grid; width: 31px; height: 31px; place-items: center; border-radius: 10px 10px 4px 10px; background: var(--tamarind); color: white; font-family: "Noto Sans Thai", sans-serif; font-size: 26px; font-weight: 700; line-height: 1; padding-bottom: 8px; }
.brand-name { font-size: 15px; font-weight: 800; letter-spacing: -0.035em; white-space: nowrap; }
.brand-name span { margin-left: 3px; color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: 0; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.network-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 12%, transparent); }
.network-status.offline .status-dot { background: var(--danger); box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 12%, transparent); }
.icon-button { display: inline-grid; width: 44px; min-width: 44px; height: 44px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--navy); transition: background 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease; }
.icon-button:hover:not(:disabled) { border-color: #bdcbd4; background: var(--mist); }
.icon-button:active:not(:disabled) { background: #e3edf1; }
.icon-button:disabled { opacity: 0.42; }
.icon-button svg, .text-button svg, .danger-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.install-button { color: var(--tamarind); }

.workspace { width: min(1180px, 100%); margin: 0 auto; padding: 18px 16px calc(28px + var(--safe-bottom)); }


.intro { position: relative; max-width: 680px; margin-bottom: 28px; }
.eyebrow, .panel-kicker { margin: 0; color: var(--tamarind); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.intro h1 { margin: 5px 0 8px; color: var(--navy); font-size: clamp(32px, 8vw, 58px); font-weight: 850; line-height: 1.04; letter-spacing: -0.055em; }
.intro > p:not(.eyebrow) { max-width: 620px; margin: 0; color: var(--muted); font-size: clamp(14px, 2vw, 17px); }
.balance { display: inline-flex; min-height: 34px; align-items: center; gap: 8px; margin-top: 17px; padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 12px; }
.balance-label { color: var(--navy); font-weight: 750; }
.balance.error { border-color: color-mix(in srgb, var(--danger) 28%, var(--line)); color: var(--danger); }

.translator { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-items: stretch; }
.panel { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.panel-heading h2, .dialog-heading h2 { margin: 3px 0 0; color: var(--navy); font-size: 18px; line-height: 1.25; letter-spacing: -0.025em; }
.panel-heading output { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel-heading output.warning { color: var(--tamarind); font-weight: 750; }

#source-text { display: block; width: 100%; height: 110px; min-height: 110px; margin-top: 10px; padding: 0; resize: vertical; border: 0; background: transparent; color: var(--ink); font-size: 16px; line-height: 1.6; caret-color: var(--tamarind); }
#source-text::placeholder { color: #8697a2; }
#source-text:focus { outline: 0; }
.source-panel:focus-within { border-color: #afc0cb; box-shadow: 0 0 0 4px rgba(21, 50, 74, 0.06), var(--shadow); }
.field-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.field-footer p { margin: 0; color: var(--muted); font-size: 12px; }
.inline-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.text-button { display: inline-flex; min-height: 44px; align-items: center; gap: 7px; padding: 0 9px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.text-button:hover { background: var(--mist); color: var(--navy); }
.text-button:active { background: #e3edf1; }
.field-error { margin: 10px 0 0; color: var(--danger); font-size: 13px; font-weight: 650; }
.primary-button { position: relative; display: inline-flex; width: 100%; min-height: 46px; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; padding: 0 22px; border: 0; border-radius: 14px; background: var(--navy); color: white; font-weight: 780; letter-spacing: 0.01em; transition: background 180ms ease, box-shadow 180ms ease; }
.primary-button:hover:not(:disabled) { background: var(--navy-2); box-shadow: 0 8px 22px rgba(21, 50, 74, 0.18); }
.primary-button:active:not(:disabled) { background: #10283d; }
.primary-button:disabled { opacity: 0.62; }
.button-progress { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.38); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.primary-button.loading .button-progress { display: block; }

.flow-mark { display: flex; height: 20px; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.flow-mark i { display: block; width: 34px; height: 1px; background: var(--line); }
.result-panel { min-height: 180px; background: linear-gradient(145deg, #f4f8fa 0%, var(--surface) 62%); }
.result-empty { display: grid; min-height: 112px; place-content: center; justify-items: center; padding: 12px 10px; text-align: center; }
.result-glyph { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid var(--line); border-radius: 16px 16px 6px 16px; background: var(--surface); color: var(--tamarind); font-family: "Noto Serif SC", serif; font-size: 21px; box-shadow: 0 12px 28px rgba(20, 37, 50, .07); }
.result-empty p { margin: 8px 0 0; color: var(--navy); font-weight: 750; }
.result-empty small { max-width: 280px; color: var(--muted); font-size: 12px; }
.result-content { padding-top: 12px; }
.result-text { margin: 0; color: var(--ink); font-size: clamp(17px, 2vw, 20px); line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.result-meta { margin: 20px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.result-details { display: grid; gap: 8px; margin-top: 12px; }
.result-details details { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.result-details summary { min-height: 44px; padding: 10px 12px; color: var(--navy); font-size: 13px; font-weight: 750; cursor: pointer; }
.result-details ul { margin: 0; padding: 0 16px 14px 32px; color: var(--muted); font-size: 13px; }
.result-panel.loading .result-empty { opacity: .42; }
.global-status { min-height: 24px; margin: 14px 2px 0; color: var(--muted); font-size: 13px; }
.global-status.error { color: var(--danger); }

.app-dialog { width: min(520px, calc(100% - 24px)); max-height: min(760px, calc(100dvh - 24px)); padding: 0; overflow: hidden auto; border: 0; border-radius: 24px; background: transparent; color: var(--ink); box-shadow: 0 30px 90px rgba(9, 25, 37, .25); }
.app-dialog::backdrop { background: rgba(10, 27, 39, .58); backdrop-filter: blur(5px); }
.dialog-card { padding: 22px; background: var(--surface); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-intro { margin: 14px 0 20px; color: var(--muted); font-size: 14px; }
.settings-status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: -4px 0 18px; }
.settings-status .balance { margin-top: 0; }
.field-label { display: block; margin-bottom: 7px; color: var(--navy); font-size: 13px; font-weight: 750; }
.password-field { display: grid; grid-template-columns: 1fr 44px; gap: 8px; }
.password-field input { min-width: 0; min-height: 48px; padding: 10px 12px; border: 1px solid #b9c8d2; border-radius: 13px; background: var(--paper); color: var(--ink); }
.password-field input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(21, 50, 74, .08); outline: 0; }
.check-row { display: flex; min-height: 54px; align-items: flex-start; gap: 12px; margin-top: 13px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 13px; cursor: pointer; }
.check-row input { width: 19px; height: 19px; margin: 2px 0 0; accent-color: var(--navy); }
.check-row span { display: grid; gap: 1px; }
.check-row strong { color: var(--navy); font-size: 14px; }
.check-row small, .privacy-note { color: var(--muted); font-size: 12px; }
.settings-feature { display: flex; min-height: 64px; align-items: center; justify-content: space-between; gap: 14px; margin-top: 13px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; }
.settings-feature > div { display: grid; gap: 1px; }
.settings-feature strong { color: var(--navy); font-size: 14px; }
.settings-feature small { color: var(--muted); font-size: 12px; }
.secondary-button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 0 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--navy); font-weight: 750; text-decoration: none; }
.secondary-button:hover:not(:disabled) { border-color: #b8c8d2; background: var(--mist); }
.secondary-button:active:not(:disabled) { background: #e3edf1; }
.secondary-button:disabled { cursor: not-allowed; opacity: .48; }
.privacy-note { margin: 14px 3px 0; }
.shortcut-dialog-card { display: grid; }
.shortcut-token-state { min-height: 42px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--muted); font-size: 13px; }
.shortcut-token-state.ready { color: var(--success); }
.shortcut-token-state.error { color: var(--danger); }
.shortcut-primary-button { margin-top: 10px; }
.shortcut-credential-summary { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.shortcut-credential-summary .danger-button { margin-top: 0; }
.shortcut-details { margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; }
.shortcut-details summary { min-height: 44px; padding: 10px 12px; color: var(--navy); font-size: 13px; font-weight: 750; cursor: pointer; }
.shortcut-details dl { display: grid; gap: 10px; margin: 0; padding: 0 12px 14px; }
.shortcut-details dl div { display: grid; gap: 2px; }
.shortcut-details dt { color: var(--muted); font-size: 11px; font-weight: 750; }
.shortcut-details dd { min-width: 0; margin: 0; }
.shortcut-details code { display: block; overflow-wrap: anywhere; color: var(--ink); font-size: 12px; white-space: normal; }
.shortcut-credential-value { margin: 0 12px 10px; padding: 10px; border-radius: 9px; background: var(--paper); }
.shortcut-credential-value code { user-select: all; }
.shortcut-details .secondary-button { width: calc(100% - 24px); margin: 0 12px 12px; }
.shortcut-steps { display: grid; gap: 12px; margin: 0; padding: 0 12px 14px; list-style: none; counter-reset: shortcut-step; }
.shortcut-steps li { display: grid; grid-template-columns: 28px 1fr; gap: 2px 10px; counter-increment: shortcut-step; }
.shortcut-steps li::before { grid-row: 1 / 3; content: counter(shortcut-step); display: grid; width: 28px; height: 28px; place-items: center; border-radius: 9px; background: var(--mist); color: var(--navy); font-size: 12px; font-weight: 800; }
.shortcut-steps strong { color: var(--navy); font-size: 14px; }
.shortcut-steps span { color: var(--muted); font-size: 12px; }
.history-list { display: grid; gap: 9px; max-height: 58dvh; margin-top: 18px; overflow: auto; }
.history-empty { margin: 30px 0; color: var(--muted); text-align: center; }
.history-entry { display: grid; width: 100%; grid-template-columns: 1fr 24px; gap: 5px 10px; min-height: 76px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); text-align: left; }
.history-entry:hover { border-color: #b8c8d2; background: var(--mist); }
.history-entry strong, .history-entry span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-entry strong { color: var(--navy); font-size: 14px; }
.history-entry span { grid-column: 1; color: var(--muted); font-size: 12px; }
.history-entry time { grid-column: 1; color: #788a95; font-size: 11px; }
.history-entry svg { grid-column: 2; grid-row: 1 / 4; align-self: center; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.danger-button { display: inline-flex; min-height: 44px; align-items: center; gap: 8px; margin-top: 16px; padding: 0 10px; border: 0; border-radius: 10px; background: transparent; color: var(--danger); font-size: 13px; font-weight: 750; }
.danger-button:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.danger-button:disabled { cursor: not-allowed; opacity: .48; }
.compact-dialog { padding-bottom: 26px; }
.install-steps { display: grid; gap: 14px; margin: 22px 0 0; padding-left: 24px; color: var(--muted); }
.install-steps li::marker { color: var(--tamarind); font-weight: 800; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); padding: 11px 15px; border-radius: 12px; background: #10283d; color: white; font-size: 13px; font-weight: 650; box-shadow: 0 12px 32px rgba(10, 27, 39, .25); }

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

@media (min-width: 620px) {
  .header-inner, .workspace { padding-left: 28px; padding-right: 28px; }

  .panel { padding: 26px; }
  #source-text { height: 200px; min-height: 200px; margin-top: 16px; font-size: 17px; line-height: 1.7; }
  .result-panel { min-height: 320px; }
  .result-empty { min-height: 215px; }
  .dialog-card { padding: 28px; }
}

@media (min-width: 920px) {
  .workspace { padding-top: 52px; }
  .intro { margin-bottom: 36px; }
  .translator { grid-template-columns: minmax(0, 1fr) 56px minmax(0, 1fr); gap: 0; }
  .flow-mark { height: 100%; flex-direction: column; }
  .flow-mark i { width: 1px; height: 46px; }
  .panel { min-height: 400px; }
  #source-text { height: 220px; min-height: 220px; }
  .result-panel { min-height: 400px; }
  .result-empty { min-height: 275px; }
}

@media (max-width: 460px) {
  .header-inner { gap: 8px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-header { position: static; }
  .workspace { padding-top: 22px; }
  .intro h1 { font-size: 32px; }
  #source-text { height: 90px; min-height: 90px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #edf4f7;
    --navy: #dceaf1;
    --navy-2: #b9d3df;
    --tamarind: #f08a5d;
    --paper: #0d1820;
    --surface: #14232d;
    --mist: #1b303c;
    --line: #334955;
    --muted: #b2c1c9;
    --danger: #ff9a7a;
    --success: #70c89c;
    --focus: #ffad75;
    --shadow: 0 18px 60px rgba(0, 0, 0, .22);
  }
  .app-header { background: color-mix(in srgb, var(--paper) 90%, transparent); }
  .brand-mark, .primary-button { color: #fff; }
  .primary-button { background: #285979; }
  .primary-button:hover:not(:disabled) { background: #326b90; }
  .result-panel { background: linear-gradient(145deg, #172c37 0%, var(--surface) 62%); }
  #source-text::placeholder { color: #91a2ac; }
  .password-field input { border-color: var(--line); }
  .toast { background: #e8f2f7; color: #10212c; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
