:root {
  --ink: #14202b;
  --ink-soft: #3d4f5f;
  --paper: #f3f0ea;
  --foam: rgba(255, 252, 247, 0.86);
  --line: rgba(20, 32, 43, 0.14);
  --accent: #0f7a6e;
  --accent-ink: #04352f;
  --err: #b42318;
  --ok: #067647;
  --font-brand: "Syne", "IBM Plex Sans TC", sans-serif;
  --font-body: "IBM Plex Sans TC", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.18em; }

/* ---- Full-bleed sky ---- */
.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.sky__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  transform: scale(1.06);
  animation: drift 28s var(--ease) infinite alternate;
}

/* Default (未選裝置): 用螢幕寬度切換 */
.sky__img--pc { display: block; }
.sky__img--mobile { display: none; }

@media (max-width: 768px) {
  .sky__img--pc { display: none; }
  .sky__img--mobile { display: block; }
}

/* 登入後選了 PC / 手機: 以選擇為準 */
body.ui-pc .sky__img--pc { display: block; }
body.ui-pc .sky__img--mobile { display: none; }
body.ui-mobile .sky__img--pc { display: none; }
body.ui-mobile .sky__img--mobile { display: block; }

/* 裝置選擇頁：只用手機底圖，強制顯示 */
body.page-device .sky__img--mobile {
  display: block !important;
  object-position: center top;
}
body.page-device .sky__img--pc {
  display: none !important;
}

.sky__wash {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(243, 240, 234, 0.18) 0%, rgba(243, 240, 234, 0.55) 55%, rgba(243, 240, 234, 0.88) 100%),
    radial-gradient(900px 520px at 70% 20%, rgba(255, 255, 255, 0.35), transparent 60%);
}

@keyframes drift {
  from { transform: scale(1.06) translate3d(0, 0, 0); }
  to   { transform: scale(1.1) translate3d(-1.5%, -1%, 0); }
}

/* ---- Motion ---- */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  animation: rise 0.9s var(--ease) forwards;
}

.reveal--delay-1 { animation-delay: 0.12s; }
.reveal--delay-2 { animation-delay: 0.24s; }
.reveal--delay-3 { animation-delay: 0.36s; }

@keyframes rise {
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sky__img { animation: none; }
  .reveal { opacity: 1; transform: none; animation: none; }
}

/* ---- Top bar ---- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  padding: 1rem clamp(1rem, 4vw, 2rem) 0.35rem;
}

.topbar__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.45rem 0.85rem;
  background: var(--foam);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar__who {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.topbar__link {
  color: var(--ink);
  font-weight: 500;
  font-size: 0.92rem;
}

/* ---- Home stage: centered + top ---- */
.page-home { overflow-x: hidden; }

.stage {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  min-height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  padding: 0.75rem clamp(1.1rem, 5vw, 2.5rem) 2rem;
}

.stage__brand {
  margin: 0;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: clamp(3.2rem, 12vw, 7.5rem);
  line-height: 0.92;
  letter-spacing: -0.04em;
  color: var(--ink);
}

.stage__title {
  margin: 1.1rem 0 0;
  max-width: 22ch;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(1.35rem, 2.8vw, 1.85rem);
  line-height: 1.35;
  color: var(--ink);
}

.stage__lede {
  margin: 0.75rem 0 0;
  max-width: 32ch;
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

.stage__cta {
  margin-top: 1.6rem;
  display: flex;
  justify-content: center;
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 45px;
  padding: 0 20px;
  border: 2px solid var(--ai-cream, #f8f8f0);
  border-radius: 50px;
  background: var(--ai-cream, #f8f8f0);
  color: var(--ai-warm, #794f27);
  font-family: Nunito, "Noto Sans SC", var(--font-body);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 5px 0 0 var(--ai-shadow-warm, #bdaea0);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:hover {
  text-decoration: none;
  color: var(--ai-warm, #794f27);
  transform: translateY(-1px);
  box-shadow: 0 6px 0 0 var(--ai-shadow-warm, #bdaea0);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 0 var(--ai-shadow-warm, #bdaea0);
}

.btn--ghost {
  background: var(--ai-bg, #f8f8f0);
  color: var(--ai-text, #794f27);
  border-color: var(--ai-border, #aaa69d);
  box-shadow: 0 2px 4px 0 rgba(61, 52, 40, 0.06);
}

.btn--ghost:hover {
  color: var(--ai-primary, #19c8b9);
  border-color: var(--ai-primary, #19c8b9);
  background: var(--ai-bg, #f8f8f0);
  box-shadow: 0 3px 10px 0 rgba(61, 52, 40, 0.1);
}

/* ---- Login gate ---- */
.page-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.gate {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  padding: 1.75rem 1.5rem 1.4rem;
  background: var(--foam);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.gate__brand {
  display: inline-block;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-decoration: none;
}

.gate__brand:hover { text-decoration: none; color: var(--accent); }

.gate__title {
  margin: 1.1rem 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.gate__form { margin-top: 0.5rem; }

.field {
  display: block;
  margin: 0.85rem 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.field input {
  display: block;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font: inherit;
}

.field input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, white);
  outline-offset: 1px;
}

.gate .btn { width: 100%; margin-top: 0.6rem; }

.gate__back {
  margin: 1rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.form-msg { margin: 0.75rem 0 0; font-size: 0.92rem; }
.form-msg--err { color: var(--err); }

/* ---- Admin (functional panel, same tokens) ---- */
.site-header {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.35rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
  text-decoration: none;
}

.site-header nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.muted { color: var(--ink-soft); }
.error, .ok { margin: 0.5rem 0 1rem; }
.error { color: var(--err); }
.ok { color: var(--ok); }

.admin {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.admin h1 {
  font-family: var(--font-brand);
  font-size: 1.8rem;
  margin: 0 0 0.5rem;
}

.admin h2 {
  margin-top: 2rem;
  font-size: 1.05rem;
}

.admin input,
.admin select {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.admin button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f8f8f0;
  color: #794f27;
  border: 2px solid #f8f8f0;
  border-radius: 50px;
  padding: 0.45rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 0 0 #bdaea0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.admin button:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 0 #bdaea0;
}

.admin button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 0 #bdaea0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 1rem 0 2rem;
  background: #fff;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.45rem;
  text-align: left;
  vertical-align: top;
}

.row-form, .actions, .inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.row-form input,
.row-form select { width: auto; min-width: 140px; }

.inline input { width: 120px; }
.inline button { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

@media (max-width: 640px) {
  .stage {
    justify-content: flex-start;
    align-items: center;
    text-align: center;
    min-height: auto;
  }
  .stage__brand { font-size: clamp(2.8rem, 16vw, 4.2rem); }
  table { display: block; overflow-x: auto; }
}

/* ---- Device picker ---- */
.page-device {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.device-pick {
  position: relative;
  z-index: 1;
  width: min(100%, 640px);
  padding: 1.75rem 1.4rem 1.5rem;
  background: var(--foam);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.device-pick__brand {
  margin: 0;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}

.device-pick__title {
  margin: 1rem 0 0.4rem;
  font-size: 1.35rem;
  font-weight: 600;
}

.device-pick__lede {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.55;
  font-size: 0.98rem;
}

.device-pick__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-top: 1.35rem;
}

.device-pick__grid form { margin: 0; }

.device-card {
  width: 100%;
  min-height: 8.5rem;
  padding: 1.15rem 1rem;
  border: 2px solid #d4c4a8;
  border-radius: 20px;
  background:
    radial-gradient(circle, rgba(196, 184, 158, 0.15) 1.5px, transparent 1.5px),
    radial-gradient(circle, rgba(196, 184, 158, 0.1) 1px, transparent 1px),
    rgb(247, 243, 223);
  background-size: 28px 28px, 14px 14px;
  background-position: 0 0, 7px 7px;
  color: #725d42;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.35rem;
  font-family: Nunito, "Noto Sans SC", var(--font-body);
  box-shadow: 0 5px 0 0 #bdaea0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.device-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 0 0 #bdaea0;
  border-color: #19c8b9;
}

.device-card:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 0 #bdaea0;
}

.device-card.is-hint {
  outline: 2px solid #19c8b9;
  outline-offset: 2px;
}

.device-card__label {
  font-family: Nunito, "Noto Sans SC", var(--font-brand);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  color: #794f27;
}

.device-card__hint {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.4;
}

.device-pick__who {
  margin: 1.1rem 0 0;
  font-size: 0.88rem;
}

@media (max-width: 560px) {
  .device-pick__grid { grid-template-columns: 1fr; }
  .device-card { min-height: 6.5rem; }
}

/* ---- Layout modes after choice ---- */
body.ui-pc {
  --stage-max: 1100px;
  --brand-size: clamp(3.6rem, 11vw, 7.5rem);
  --title-size: clamp(1.4rem, 2.4vw, 1.9rem);
  --lede-size: 1.05rem;
  --tap: 2.75rem;
}

body.ui-mobile {
  --stage-max: 390px; /* iPhone 14/15 logical width */
  --brand-size: clamp(2.4rem, 12vw, 3.2rem);
  --title-size: 1.2rem;
  --lede-size: 0.98rem;
  --tap: 3.1rem;
  --iphone-ratio: 390 / 844;
}

/* 手機模式：內容欄固定 iPhone 寬，整頁置中 */
body.ui-mobile.page-home {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100svh;
  min-height: 100dvh;
}

body.ui-mobile .topbar {
  width: min(100%, var(--stage-max));
  padding: max(0.65rem, env(safe-area-inset-top)) 0.75rem 0.25rem;
  justify-content: center;
  box-sizing: border-box;
}

body.ui-mobile .topbar__nav {
  width: 100%;
  max-width: 100%;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

body.ui-mobile .stage {
  width: min(100%, var(--stage-max));
  max-width: var(--stage-max);
  margin: 0 auto;
  padding: 0.5rem 1rem max(1.5rem, env(safe-area-inset-bottom));
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  box-sizing: border-box;
}

/* 未登入但窄螢幕：同樣用 iPhone 欄寬 */
@media (max-width: 768px) {
  body.page-home.ui-unknown {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  body.page-home.ui-unknown .topbar,
  body.page-home.ui-unknown .stage {
    width: min(100%, 390px);
    max-width: 390px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
  }

  body.page-home.ui-unknown .topbar {
    padding-top: max(0.65rem, env(safe-area-inset-top));
    justify-content: center;
  }

  body.page-home.ui-unknown .stage {
    padding: 0.5rem 1rem max(1.5rem, env(safe-area-inset-bottom));
    justify-content: flex-start;
    align-items: center;
    text-align: center;
  }
}

body.ui-pc .stage {
  max-width: var(--stage-max);
  margin: 0 auto;
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  padding-top: 0.75rem;
  padding-bottom: 2rem;
}

body.ui-pc .stage__brand,
body.ui-mobile .stage__brand {
  font-size: var(--brand-size);
}

body.ui-pc .stage__title,
body.ui-mobile .stage__title {
  font-size: var(--title-size);
}

body.ui-pc .stage__lede,
body.ui-mobile .stage__lede {
  font-size: var(--lede-size);
}

body.ui-mobile .btn {
  min-height: var(--tap);
  width: 100%;
  max-width: 100%;
  font-size: 1.05rem;
}

body.ui-mobile .topbar__link {
  font-size: 1rem;
  padding: 0.25rem 0;
}

body.ui-pc .admin {
  max-width: 1100px;
  font-size: 0.95rem;
}

body.ui-mobile .admin {
  width: min(100%, 390px);
  max-width: 390px;
  margin: 0 auto;
  padding: 1rem 0.85rem max(2rem, env(safe-area-inset-bottom));
  font-size: 1rem;
}

body.ui-mobile .admin button,
body.ui-mobile .inline button {
  min-height: 2.75rem;
}

body.ui-mobile .row-form {
  flex-direction: column;
  align-items: stretch;
}

body.ui-mobile .row-form input,
body.ui-mobile .row-form select {
  width: 100%;
  min-width: 0;
}
