@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;500;600;700;800;900&display=swap');

:root {
  --ink: #2c2016;
  --brown: #3a2d21;
  --paper: #f6e9bf;
  --paper-light: #fff8e6;
  --red: #9f281f;
  --red-bright: #cf2a2f;
  --teal: #56b9b3;
  --gold: #d89537;
  --line: rgba(44, 32, 22, 0.72);
  --serif: "Noto Serif TC", "SimSun", "宋體", "NSimSun", "Source Han Serif TC", "PMingLiU", serif;
  --sans: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  background-color: #cbb98b;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(58, 45, 33, 0.13) 1px, transparent 1.2px),
    linear-gradient(130deg, rgba(255,255,255,.12), transparent 40%);
  background-size: 7px 7px, auto;
}

.time-travel-banner {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  background: var(--red);
  color: #fff8e5;
  font-size: clamp(14px, 1.35vw, 18px);
  font-weight: 800;
  letter-spacing: .08em;
  text-align: center;
}

.time-travel-banner::before,
.time-travel-banner::after {
  content: "◆";
  margin: 0 12px;
  color: var(--gold);
  font-size: .8em;
}

button, input { font: inherit; }
button { cursor: pointer; }

.site-shell {
  width: min(100%, 1060px);
  min-height: 100vh;
  margin: 0 auto;
  background: rgba(246, 233, 191, 0.94);
  border-inline: 1px solid var(--line);
  box-shadow: 0 0 38px rgba(44, 32, 22, .18);
}

.masthead {
  min-height: 116px;
  padding: 22px clamp(18px, 4vw, 48px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  color: var(--paper);
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 2px, transparent 2px 6px),
    var(--brown);
  border-bottom: 6px double #b88a49;
}

.office-mark {
  display: grid;
  place-items: center;
  width: 68px;
  aspect-ratio: 1;
  border: 3px double #d5b87d;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.kicker, .eyebrow {
  margin: 0 0 6px;
  font: 700 11px/1.5 var(--sans);
  letter-spacing: .18em;
  text-transform: uppercase;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(29px, 5vw, 48px);
  line-height: 1.1;
  letter-spacing: .08em;
}

.department { margin: 6px 0 0; font-weight: 700; letter-spacing: .12em; }
.document-number { text-align: center; font-size: 13px; line-height: 1.6; }

.hero {
  position: relative;
  min-height: 310px;
  padding: 54px clamp(24px, 6vw, 76px);
  display: flex;
  align-items: center;
  overflow: hidden;
  color: #fff6dd;
  background: var(--red-bright);
  border-bottom: 10px solid var(--gold);
}

.hero::after {
  content: "";
  position: absolute;
  inset: 15px;
  border: 1px solid rgba(255, 246, 221, .38);
  pointer-events: none;
}

.hero-copy { position: relative; z-index: 2; max-width: 620px; }
.hero h2 { margin: 0; font-size: clamp(52px, 10vw, 96px); line-height: .98; letter-spacing: .04em; }
.hero-copy > p:last-child { margin: 24px 0 0; max-width: 34em; font-size: 17px; line-height: 1.85; }
.mobile-break { display: none; }

.hero-building {
  position: absolute;
  z-index: 1;
  width: min(47%, 470px);
  right: -36px;
  bottom: -22px;
  opacity: .23;
  filter: sepia(.25);
}

.hero-flower {
  position: absolute;
  width: 300px;
  left: -80px;
  bottom: -105px;
  opacity: .15;
  transform: rotate(-5deg);
}

.paper-panel, .result-panel, .notice {
  margin: clamp(24px, 5vw, 58px);
  padding: clamp(22px, 4vw, 48px);
  background-color: var(--paper-light);
  background-image: linear-gradient(120deg, rgba(216,149,55,.06), transparent 45%);
  border: 4px double var(--ink);
  box-shadow: 10px 12px 0 rgba(58, 45, 33, .12);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 3px double var(--ink);
}

.panel-heading p, .result-header p { margin: 0 0 4px; font-size: 14px; letter-spacing: .12em; }
.panel-heading h2 { margin: 0; font-size: clamp(30px, 5vw, 44px); }

.stamp {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 94px;
  aspect-ratio: 1.55;
  color: var(--red);
  border: 3px double var(--red);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  transform: rotate(-4deg);
}

form > label { display: block; margin-bottom: 10px; font-weight: 800; font-size: 18px; }

.residence-fieldset { margin: 0 0 24px; padding: 0; border: 0; }
.residence-fieldset legend { padding: 0; color: var(--ink); font-size: 18px; font-weight: 800; }
.residence-help { margin: 8px 0 14px; color: #776858; font-size: 13px; line-height: 1.7; }
.residence-layout { display: grid; grid-template-columns: minmax(150px, 190px) minmax(0, 1fr); gap: 18px; align-items: start; }
.residence-map { margin: 0; padding: 7px; border: 1px solid var(--line); background: #fffaf0; }
.residence-map img { display: block; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; }
.residence-map figcaption { margin-top: 7px; color: #776858; font-size: 11px; text-align: center; letter-spacing: .08em; }
.residence-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.residence-option { position: relative; display: flex; flex-direction: column; gap: 3px; min-height: 57px; padding: 10px; color: var(--ink); border: 1px solid var(--line); background: rgba(255,250,240,.55); cursor: pointer; }
.residence-option input { position: absolute; opacity: 0; pointer-events: none; }
.residence-option span { font-weight: 800; }
.residence-option small { color: #776858; font: 700 10px/1.2 var(--sans); letter-spacing: .12em; }
.residence-option.selected { color: #fff8e5; border-color: var(--brown); background: var(--brown); }
.residence-option.selected small { color: #e7cf97; }
.residence-option:focus-within { outline: 2px solid var(--red); outline-offset: 2px; }
.residence-result { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: -12px 0 28px; color: var(--red); text-align: center; }
.residence-result span { color: #776858; font-size: 13px; letter-spacing: .12em; }
.residence-result strong { font-size: 20px; }

.input-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.mobile-residence-submit { display: none; }

input {
  min-width: 0;
  width: 100%;
  height: 58px;
  padding: 0 16px;
  color: var(--ink);
  background: #fffaf0;
  border: 2px solid var(--ink);
  border-radius: 0;
  font-size: 19px;
  outline: none;
}
input:focus { box-shadow: 0 0 0 3px rgba(207, 42, 47, .2); border-color: var(--red); }

.primary-button, .secondary-button {
  min-height: 52px;
  padding: 0 26px;
  border: 1px solid var(--red);
  font-weight: 800;
  letter-spacing: .08em;
}
.primary-button { color: #fff8e5; background: var(--red); }
.primary-button:hover { background: #7e1d18; }
.secondary-button { color: var(--red); background: transparent; }
.secondary-button:hover { background: rgba(159, 40, 31, .08); }

.form-help { margin: 10px 0 0; color: #776858; font-size: 13px; }
.form-error, .copy-status { min-height: 1.5em; margin: 8px 0 0; color: var(--red); font-weight: 700; }

.result-panel { border-color: var(--red); }
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.result-header span { color: var(--red); font-size: 24px; font-weight: 800; letter-spacing: .25em; }

.name-conversion {
  margin: 30px 0;
  padding: 30px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 22px;
  border: 3px double var(--ink);
  text-align: center;
}
.name-conversion small { display: block; margin-bottom: 8px; color: #786a5c; letter-spacing: .12em; }
.name-conversion strong { display: block; font-size: clamp(30px, 6vw, 50px); line-height: 1.2; overflow-wrap: anywhere; }
.name-conversion > div:last-child strong { color: var(--red); }
.arrow { color: var(--red); font-size: 42px; }

.welcome-copy { text-align: center; }
.welcome-copy h2 { margin: 8px auto 18px; font-size: clamp(30px, 6vw, 54px); line-height: 1.35; text-wrap: balance; }
.welcome-copy p:not(.eyebrow) { max-width: 42em; margin: 12px auto; font-size: 17px; line-height: 1.9; }
.result-actions { margin-top: 28px; display: flex; justify-content: center; gap: 12px; }
.copy-status { text-align: center; }

.notice { border-width: 1px; box-shadow: none; }
.notice h2 { margin: 0 0 16px; font-size: 26px; }
.notice ol { margin: 0; padding-left: 1.5em; line-height: 1.9; }
.text-button { margin-top: 14px; padding: 5px 0; color: var(--red); background: transparent; border: 0; border-bottom: 1px solid currentColor; }

footer {
  padding: 28px clamp(22px, 5vw, 58px);
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: var(--paper);
  background: var(--brown);
  font-size: 13px;
  letter-spacing: .08em;
}
footer p { margin: 0; }

[hidden] { display: none !important; }

@media (max-width: 660px) {
  .time-travel-banner {
    min-height: 38px;
    padding: 7px 12px;
    font-size: 13px;
    letter-spacing: .035em;
    white-space: nowrap;
  }

  .time-travel-banner::before,
  .time-travel-banner::after {
    margin: 0 7px;
  }

  .residence-layout { grid-template-columns: 1fr; }
  .residence-map { width: min(210px, 100%); margin-inline: auto; }
  .residence-options { gap: 7px; }
  .residence-option { min-height: 52px; padding: 9px 8px; font-size: 14px; }
  .residence-option small { font-size: 9px; }
  .residence-result { flex-direction: column; gap: 2px; margin: -10px 0 22px; }
  .site-shell { border: 0; }
  .masthead { min-height: 96px; padding: 14px 16px; gap: 12px; }
  .office-mark { width: 52px; font-size: 14px; }
  .masthead h1 { font-size: 26px; letter-spacing: .04em; }
  .masthead .kicker { display: none; }
  .department { font-size: 12px; }
  .document-number { font-size: 10px; }

  .hero { min-height: 0; padding: 46px 25px 54px; align-items: flex-start; }
  /* 手機版標題與受理說明維持單行，避免被迫拆成兩段。 */
  .hero h2 { font-size: clamp(44px, 13vw, 58px); white-space: nowrap; letter-spacing: .015em; }
  .hero-copy > p:last-child { max-width: 23em; font-size: 14px; line-height: 1.7; }
  .mobile-break { display: none; }
  .hero-building { width: 77%; right: -70px; bottom: -16px; opacity: .2; }
  .hero-flower { width: 220px; left: -80px; bottom: -82px; }

  .paper-panel, .result-panel, .notice { margin: 22px 14px; padding: 20px 17px; box-shadow: 5px 6px 0 rgba(58,45,33,.11); }
  .panel-heading { align-items: flex-start; }
  .panel-heading p { white-space: nowrap; font-size: 11px; letter-spacing: .055em; }
  .panel-heading h2 { font-size: 28px; }
  .stamp { width: 72px; font-size: 13px; }
  .input-row { grid-template-columns: 1fr; }
  input { height: 54px; font-size: 15px; }
  .input-row .primary-button { display: none; }
  .mobile-residence-submit { display: block; width: 100%; margin: -4px 0 18px; }

  .result-header span { font-size: 17px; }
  .name-conversion { padding: 22px 12px; grid-template-columns: 1fr; gap: 10px; }
  .name-conversion strong { font-size: clamp(23px, 7.5vw, 32px); white-space: nowrap; overflow-wrap: normal; }
  .arrow { font-size: 28px; transform: rotate(90deg); }
  .welcome-copy h2 { font-size: 29px; }
  .welcome-copy p:not(.eyebrow) { font-size: 14px; }
  .result-actions { flex-direction: column; }
  .result-actions button { width: 100%; }
  footer { flex-direction: column; text-align: center; }
}

@media (prefers-reduced-motion: no-preference) {
  .result-panel:not([hidden]) { animation: reveal .45s ease-out both; }
  @keyframes reveal { from { opacity: 0; transform: translateY(14px); } }
}
