:root {
  --bg: #f6f3ef;
  --card: #ffffff;
  --ink: #2c2825;
  --muted: #6b6560;
  --accent: #c47a5a;
  --accent-dark: #9e5d42;
  --ok: #2d7a4f;
  --warn: #b8860b;
  --danger: #b33a3a;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(44, 40, 37, 0.08);
  --touch: 48px;
  --space: clamp(12px, 3.2vw, 20px);
  --font: "PingFang TC", "Noto Sans TC", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font);
  background: linear-gradient(160deg, #f9f6f2 0%, #efe8e0 100%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
}

img,
video,
svg {
  max-width: 100%;
  height: auto;
}

.shell {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding:
    max(var(--space), env(safe-area-inset-top))
    max(var(--space), env(safe-area-inset-right))
    max(calc(var(--space) * 2), env(safe-area-inset-bottom))
    max(var(--space), env(safe-area-inset-left));
}

header.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: var(--space);
}

.brand {
  font-weight: 700;
  font-size: clamp(1.05rem, 4.5vw, 1.25rem);
  letter-spacing: 0.02em;
  line-height: 1.3;
  max-width: 100%;
  word-break: break-word;
}

.brand span {
  color: var(--accent-dark);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space);
  margin-bottom: var(--space);
  width: 100%;
  overflow: hidden;
}

h1 {
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  margin: 0 0 0.5rem;
}

h2 {
  font-size: clamp(1.15rem, 4.5vw, 1.45rem);
  margin: 0 0 0.5rem;
}

h3 {
  font-size: clamp(1rem, 4vw, 1.2rem);
  margin: 0 0 0.35rem;
}

.muted {
  color: var(--muted);
  font-size: clamp(0.88rem, 3.6vw, 0.95rem);
}

label {
  display: block;
  font-weight: 600;
  margin: 14px 0 8px;
  font-size: 0.95rem;
}

input[type="email"],
input[type="password"],
input[type="text"],
select {
  width: 100%;
  max-width: 100%;
  min-height: var(--touch);
  padding: 12px 14px;
  border: 1px solid #ddd5cc;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%236b6560' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  min-height: var(--touch);
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  background: var(--accent);
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn:hover {
  background: var(--accent-dark);
}

.btn.secondary {
  background: #e8e2db;
  color: var(--ink);
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

@media (min-width: 480px) {
  .btn-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .btn-row .btn:not(.block) {
    width: auto;
  }
}

.steps {
  display: grid;
  gap: 12px;
  width: 100%;
}

.step {
  border: 1px dashed #d8cfc5;
  border-radius: var(--radius);
  padding: var(--space);
  width: 100%;
}

.step.active {
  border-color: var(--accent);
  background: #fff9f5;
}

.file-field {
  margin-top: 12px;
}

.file-field input[type="file"] {
  width: 100%;
  max-width: 100%;
  min-height: var(--touch);
  font-size: 16px;
  padding: 10px;
  border: 1px solid #ddd5cc;
  border-radius: 10px;
  background: #faf8f6;
}

.preview {
  margin-top: 12px;
  width: 100%;
  max-width: 100%;
  max-height: min(42vh, 280px);
  object-fit: contain;
  border-radius: 10px;
  display: none;
  background: #f3ede7;
}

.preview.visible {
  display: block;
}

.result-block {
  white-space: pre-wrap;
  line-height: 1.65;
  word-break: break-word;
  font-size: clamp(0.9rem, 3.8vw, 1rem);
}

.result-block p {
  margin: 0 0 1rem;
}

.score-high { color: var(--ok); font-weight: 700; }
.score-mid { color: var(--warn); font-weight: 700; }
.score-low { color: var(--danger); font-weight: 700; }

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

table.data {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: clamp(0.82rem, 3.2vw, 0.92rem);
}

table.data th,
table.data td {
  border-bottom: 1px solid #eee;
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

table.data.compact th:nth-child(1),
table.data.compact td:nth-child(1) {
  white-space: nowrap;
}

@media (max-width: 639px) {
  table.data.responsive-stack thead {
    display: none;
  }

  table.data.responsive-stack tbody tr {
    display: block;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid #ebe4dc;
    border-radius: 12px;
    background: #faf8f6;
  }

  table.data.responsive-stack tbody td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 6px 0;
    font-size: 0.9rem;
  }

  table.data.responsive-stack tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    flex-shrink: 0;
    max-width: 42%;
  }

  table.data.responsive-stack tbody td.actions {
    display: block;
    padding-top: 10px;
  }

  table.data.responsive-stack tbody td.actions::before {
    display: none;
  }

  table.data.responsive-stack tbody td.actions .btn {
    width: 100%;
  }
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: #efe8e0;
}

.badge.admin {
  background: #ffe8d9;
  color: var(--accent-dark);
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

.nav-links a {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  padding: 4px 0;
}

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin: 10px 0;
  display: none;
  font-size: 0.95rem;
  word-break: break-word;
}

.alert.show { display: block; }
.alert.error { background: #fde8e8; color: var(--danger); }
.alert.ok { background: #e6f5ec; color: var(--ok); }

.history-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-card {
  padding: 12px 14px;
  border-radius: 12px;
  background: #faf8f6;
  border: 1px solid #ebe4dc;
  font-size: 0.92rem;
}

.history-card strong {
  display: block;
  margin-bottom: 4px;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

@media (min-width: 480px) {
  .form-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

@media (min-width: 720px) {
  .shell {
    padding-top: 28px;
  }

  .card {
    padding: 24px;
  }

  .steps.two-col {
    grid-template-columns: 1fr 1fr;
  }
}