/* เถ้าแห่งคำสาป — auth.html (บัญชีออนไลน์) · Ember Reliquary
 * Loaded AFTER styles.css: reuses its tokens (--brass, --ember, --line, --safe-*…), .btn, .pm-label,
 * .pm-input and the title-scene layers. Only page-specific rules live here. */

/* ——— page scroll (styles.css locks body for the game) ——— */
html.auth-root, html.auth-root body { height: auto; min-height: 100%; }
body.auth-page {
  overflow-x: hidden; overflow-y: auto;
  overscroll-behavior-y: auto;
  user-select: text; -webkit-user-select: text;
  min-height: 100vh; min-height: 100dvh;
}
.auth-page button, .auth-page .auth-tab { user-select: none; -webkit-user-select: none; }
.auth-page [hidden] { display: none !important; }

/* backdrop stays put while the form scrolls */
.auth-page .title-scene { position: fixed; z-index: 0; }
.auth-page .title-scene-art { filter: saturate(.75) contrast(1.08) brightness(.62); }

/* ——— shell ——— */
.auth-shell {
  position: relative; z-index: 1;
  width: min(420px, 100%);
  margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: safe center; gap: 16px;
  padding:
    max(20px, calc(var(--safe-t) + 14px))
    max(16px, calc(var(--safe-r) + 12px))
    max(20px, calc(var(--safe-b) + 14px))
    max(16px, calc(var(--safe-l) + 12px));
}

.auth-head { display: flex; flex-direction: column; align-items: center; text-align: center; }
.auth-head .title-crest-wrap { margin-bottom: 8px; transform: scale(.82); }
.auth-head h1 {
  font-size: clamp(1.75rem, 8vw, 2.3rem); font-weight: 800; letter-spacing: .05em; line-height: 1.25;
  background: linear-gradient(180deg, #fff4d4 0%, var(--gold2) 35%, var(--brass) 75%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 16px #c9a22755);
}
.auth-sub { color: #d8cfc0; margin-top: 4px; font-size: .93rem; max-width: 32ch; }

/* ——— panel card ——— */
.auth-panel {
  position: relative; overflow: hidden;
  border-radius: calc(var(--r-panel) + 4px);
  border: 1px solid color-mix(in srgb, var(--brass) 32%, var(--line));
  background: linear-gradient(165deg, #221a12f4 0%, #14100cee 48%, #0e0b09f4 100%);
  box-shadow: var(--shadow-ambient), var(--shadow-rim), var(--shadow-inset), 0 0 40px #c45c2618;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 18px 16px 18px;
  animation: authIn .4s cubic-bezier(.2,.8,.2,1) backwards;
}
.auth-panel::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, #c9a22712, transparent 26%),
              radial-gradient(ellipse 80% 45% at 50% 0%, #c45c261e, transparent 60%);
}
.auth-panel > * { position: relative; }
.auth-panel h2 {
  font-size: 1.3rem; font-weight: 800; color: var(--gold2); line-height: 1.3; text-align: center;
}
.auth-eyebrow {
  text-align: center; color: color-mix(in srgb, var(--brass) 75%, var(--mist));
  font-size: .72rem; font-weight: 700; letter-spacing: .16em; margin-bottom: 4px;
}

/* ——— tabs ——— */
.auth-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  padding: 4px; margin: -4px -2px 16px;
  border-radius: 14px; background: #0c0a09cc; border: 1px solid var(--line);
}
.auth-tab {
  appearance: none; border: 1px solid transparent; background: transparent; cursor: pointer;
  font-family: inherit; font-size: .95rem; font-weight: 700; color: var(--mist);
  min-height: var(--tap, 44px); padding: 6px 4px; border-radius: 10px;
  transition: color .15s, background .15s, border-color .15s, box-shadow .15s;
}
.auth-tab:hover { color: var(--gold2); }
.auth-tab[aria-selected="true"] {
  color: var(--gold2);
  border-color: color-mix(in srgb, var(--brass) 55%, transparent);
  background: linear-gradient(180deg, #3a2c18, #1c140c);
  box-shadow: var(--shadow-inset), 0 0 14px #c9a22722;
}
.auth-tab:focus-visible, .auth-link:focus-visible, .auth-eye:focus-visible, .auth-copy:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 2px;
}
.auth-tab:disabled { opacity: .5; cursor: not-allowed; }

/* ——— forms ——— */
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-intro { color: #d8cfc0; font-size: .9rem; line-height: var(--lh-body); }
.auth-field { display: flex; flex-direction: column; }
.auth-field .pm-label { font-size: .8rem; letter-spacing: .04em; }
.auth-field .pm-label small { font-weight: 600; color: color-mix(in srgb, var(--mist) 80%, transparent); letter-spacing: 0; }
.auth-page .pm-input {
  margin-bottom: 0; min-height: 50px; font-size: 1.05rem; padding: 12px 14px;
  user-select: text; -webkit-user-select: text;
}
.auth-page .pm-input::placeholder { color: #6e6254; font-weight: 600; }
.auth-page .pm-input[aria-invalid="true"] { border-color: color-mix(in srgb, var(--danger) 70%, var(--line)); }
.auth-input-code { letter-spacing: .12em; text-transform: uppercase; font-variant-numeric: tabular-nums; }
.auth-input-pin { letter-spacing: .3em; font-variant-numeric: tabular-nums; }
.auth-input-pin::placeholder { letter-spacing: .02em; }
.auth-hint { margin-top: 6px; font-size: .78rem; color: var(--mist); line-height: 1.45; }

.auth-pin-wrap { position: relative; display: flex; }
.auth-pin-wrap .pm-input { padding-right: 72px; }
.auth-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  min-width: 60px; min-height: 42px; padding: 0 10px;
  appearance: none; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  font-family: inherit; font-size: .8rem; font-weight: 700; color: var(--mist);
}
.auth-eye:hover { color: var(--gold2); background: #ffffff08; }

.auth-submit { width: 100%; min-height: 52px; margin-top: 2px; gap: 10px; }
.auth-submit .spin, .btn .spin {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: authSpin .7s linear infinite; display: none;
}
.btn.is-loading .spin { display: inline-block; }
.btn.is-loading { cursor: progress; }

.auth-error {
  color: #ff8a96; font-size: .88rem; font-weight: 600; line-height: 1.45;
  padding: 10px 12px; border-radius: 10px;
  background: #3a1520aa; border: 1px solid color-mix(in srgb, var(--blood) 55%, transparent);
}
.auth-error:empty { display: none; }
.auth-error .auth-link { color: #ffd0d5; }

.auth-link {
  appearance: none; background: none; border: 0; padding: 6px 2px; cursor: pointer;
  font-family: inherit; font-size: .88rem; font-weight: 700;
  color: color-mix(in srgb, var(--brass) 85%, #fff); text-decoration: underline;
  text-underline-offset: 3px; text-decoration-color: #c9a22766;
  min-height: 36px;
}
.auth-link:hover { color: var(--gold2); }
.auth-alt { text-align: center; margin-top: -4px; }

/* ——— one-time reveal ——— */
.auth-warn {
  margin: 12px 0 14px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ember-hot) 55%, var(--line));
  background: linear-gradient(180deg, #3a1c10cc, #1e100acc);
  color: #ffd9a8; font-size: .88rem; line-height: 1.5;
}
.auth-warn strong { color: #fff0d8; }
.auth-secret-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.auth-secret {
  position: relative;
  border-radius: 12px; padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--brass) 30%, var(--line));
  background: #0c0a09d9; min-width: 0;
}
.auth-secret .k { display: block; font-size: .72rem; font-weight: 700; color: var(--mist); letter-spacing: .06em; }
.auth-secret .v {
  display: block; margin-top: 8px; font-size: 1.25rem; font-weight: 800; color: var(--gold2);
  letter-spacing: .05em; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.3;
}
.auth-secret .v.muted { font-size: .9rem; color: #d8cfc0; letter-spacing: 0; font-weight: 600; }
.auth-secret-row { display: block; }
.auth-secret .auth-copy { position: absolute; top: 6px; right: 6px; min-height: 32px; }
.auth-copy {
  appearance: none; flex: none; cursor: pointer;
  min-height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: #1a1510; color: #d4c8b4;
  font-family: inherit; font-size: .76rem; font-weight: 700;
}
.auth-copy:hover { border-color: color-mix(in srgb, var(--brass) 45%, var(--line)); color: var(--gold2); }

.auth-codes-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.auth-codes-head .pm-label { margin: 0; font-size: .8rem; }
.auth-codes-head span { font-size: .74rem; color: var(--mist); }
.auth-codes {
  list-style: none; counter-reset: code;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 10px; border-radius: 12px; background: #0c0a09e6; border: 1px dashed color-mix(in srgb, var(--brass) 35%, var(--line));
}
.auth-codes li {
  counter-increment: code;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .84rem; font-weight: 700; color: #f0e2c4; letter-spacing: 0;
  padding: 6px 5px; border-radius: 6px; background: #ffffff06; white-space: nowrap;
  user-select: all; -webkit-user-select: all;
}
.auth-codes li::before { content: counter(code) "."; color: var(--brass-dim); margin-right: 4px; font-size: .74rem; user-select: none; }
.auth-reveal-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 14px; }
.auth-reveal-tools .btn { padding: 10px 8px; font-size: .9rem; min-height: 46px; width: 100%; }

.auth-check {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #0c0a0999;
  font-size: .9rem; color: #e8dccb; line-height: 1.45; margin-bottom: 12px;
  min-height: var(--tap, 44px);
}
.auth-check input { width: 22px; height: 22px; flex: none; margin-top: 1px; accent-color: var(--brass); }

/* ——— signed-in / done ——— */
.auth-who { text-align: center; margin: 8px 0 4px; }
.auth-who .id { font-size: 1.6rem; font-weight: 800; color: var(--gold2); letter-spacing: .08em; }
.auth-who .name { color: #e8dccb; font-weight: 600; }
.auth-who .meta { color: var(--mist); font-size: .8rem; margin-top: 4px; }
.auth-stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.auth-stack .btn { width: 100%; min-height: 50px; }
.auth-done-mark {
  width: 56px; height: 56px; margin: 2px auto 10px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.6rem; font-weight: 800; color: #0c0a09;
  background: radial-gradient(circle at 40% 35%, #f0dca0, var(--brass) 70%);
  box-shadow: 0 0 26px #c9a22766;
}
.auth-note { text-align: center; color: #d8cfc0; font-size: .92rem; line-height: 1.5; margin-top: 6px; }
.auth-note.warn { color: #ffcf9a; }

/* compact header while the one-time sheet is open (keeps secrets above the fold) */
body.is-reveal .auth-head .title-crest-wrap, body.is-reveal .auth-sub { display: none; }
body.is-reveal .auth-head h1 { font-size: 1.4rem; }

/* ——— footer ——— */
.auth-foot { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.auth-health {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .74rem; color: var(--mist); opacity: .85;
  padding: 4px 10px; border-radius: var(--r-pill); background: #0c0a0999; border: 1px solid #3a322888;
}
.auth-health .dot { width: 7px; height: 7px; border-radius: 50%; background: #6e6254; flex: none; }
.auth-health[data-state="ok"] .dot { background: var(--ok); box-shadow: 0 0 8px #5cbc7888; }
.auth-health[data-state="down"] .dot { background: var(--danger); box-shadow: 0 0 8px #e0506088; }
.auth-health[data-state="wait"] .dot { animation: authBlink 1s ease-in-out infinite; }
.auth-foot-note { font-size: .74rem; color: var(--mist); opacity: .8; }
.auth-back { font-size: .85rem; }

/* toast for copy feedback */
.auth-toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); z-index: 20;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: var(--r-pill);
  background: #1c1612f5; border: 1px solid color-mix(in srgb, var(--brass) 45%, var(--line));
  color: var(--gold2); font-weight: 700; font-size: .88rem; box-shadow: var(--shadow-ambient);
  white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
  transition: opacity .2s, transform .2s;
}
.auth-toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes authIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes authSpin { to { transform: rotate(360deg); } }
@keyframes authBlink { 50% { opacity: .3; } }

@media (max-width: 360px) {
  .auth-secret-grid, .auth-codes { grid-template-columns: 1fr; }
  .auth-tab { font-size: .86rem; }
}
@media (min-height: 760px) { .auth-head .title-crest-wrap { transform: scale(.9); margin-bottom: 12px; } }
@media (prefers-reduced-motion: reduce) {
  .auth-panel, .auth-toast { animation: none; transition: none; }
  .auth-health[data-state="wait"] .dot { animation: none; }
}
