:root {
  --green: #2f5d4a;
  --green-dark: #1b3d30;
  --green-soft: #e8f0eb;
  --blue: #5b9bd5;
  --blue-dark: #3d7eb5;
  --blue-soft: #e8f4fc;
  --bg: #f7f8f5;
  --card: #ffffff;
  --text: #1c2421;
  --muted: #5c6b64;
  --line: #e4ebe6;
  --gold: #c4a35a;
  --danger: #b23a3a;
  --shadow: 0 10px 30px rgba(27, 61, 48, 0.08);
  --radius: 16px;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", "DFKai-SB", "標楷體", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top right, #e8f4fc 0%, transparent 42%),
    radial-gradient(circle at bottom left, #e8f0eb 0%, transparent 38%),
    var(--bg);
  color: var(--text);
  line-height: 1.75;
  min-height: 100vh;
  font-size: 1.05rem;
}
a { color: var(--blue-dark); }
.wrap { width: min(920px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.admin-wrap { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 1.5rem 0 3rem; }

.site-bar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; font-size: 0.95rem;
}
.site-bar a { color: var(--green-dark); text-decoration: none; font-weight: 600; }
.site-bar a:hover { color: var(--blue-dark); text-decoration: underline; }

.hero { text-align: center; margin-bottom: 1.5rem; }
.hero .badge {
  display: inline-block; background: var(--blue-soft); color: var(--blue-dark);
  padding: 0.4rem 1rem; border-radius: 999px; font-size: 1rem; margin-bottom: 0.75rem; font-weight: 700;
}
.hero h1 {
  margin: 0 0 0.65rem; font-size: clamp(1.65rem, 4vw, 2.25rem);
  color: var(--green-dark); font-family: DFKai-SB, "標楷體", "Microsoft JhengHei", serif;
  line-height: 1.35;
}
.hero p { margin: 0.4rem 0; color: var(--muted); font-size: 1.08rem; }
.hero .dates {
  margin-top: 0.85rem; color: var(--blue-dark); font-weight: 700; font-size: 1.12rem;
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.4rem 1.5rem 1.55rem; margin-bottom: 1.1rem;
}
.card h2 {
  margin: 0 0 1.05rem; font-size: 1.28rem; color: var(--green-dark);
  border-left: 4px solid var(--blue); padding-left: 0.7rem;
  font-family: DFKai-SB, "標楷體", "Microsoft JhengHei", serif;
}

.field { margin-bottom: 1.05rem; }
label.q, .q {
  display: block; font-weight: 700; color: var(--green-dark); margin-bottom: 0.4rem; font-size: 1.08rem;
}
.req { color: var(--danger); margin-left: 0.15rem; }
.hint { font-size: 0.92rem; color: var(--muted); margin: 0.2rem 0 0.45rem; }

input[type="text"], input[type="tel"], input[type="email"], input[type="password"], textarea, select {
  width: 100%; padding: 0.75rem 0.85rem; border: 1px solid #cfdcd4; border-radius: 10px;
  font: inherit; font-size: 16px; background: #fbfcfb; color: var(--text);
  -webkit-appearance: none; appearance: none; min-height: 44px;
}
textarea { min-height: 120px; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(91, 155, 213, 0.45); border-color: var(--blue);
  background: #fff;
}
textarea { min-height: 110px; resize: vertical; }

.row-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
@media (max-width: 640px) {
  .row-2 { grid-template-columns: 1fr; }
}

.choice-list { display: flex; flex-direction: column; gap: 0.55rem; }
.choice {
  display: flex; align-items: flex-start; gap: 0.65rem;
  padding: 0.75rem 0.9rem; border: 1px solid var(--line); border-radius: 12px;
  background: #fbfdff; cursor: pointer; transition: border-color .15s, background .15s;
}
.choice:hover { border-color: #9ec9ea; background: var(--blue-soft); }
.choice input { margin-top: 0.25rem; width: 1.15rem; height: 1.15rem; accent-color: var(--blue-dark); flex-shrink: 0; }
.choice span { line-height: 1.5; color: var(--text); }
.choice.inline-row {
  flex-direction: row; flex-wrap: wrap; gap: 0.85rem 1.25rem; align-items: center;
}
.choice.inline-row label {
  display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; font-weight: 600; color: var(--green-dark);
}

.actions {
  display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: center; margin-top: 0.5rem;
}
.btn {
  display: inline-block; border: 0; border-radius: 999px; padding: 0.75rem 1.45rem;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--blue-soft); color: var(--blue-dark); }
.btn-secondary:hover { background: #d6ebfa; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.toast {
  display: none; margin: 0 0 1rem; padding: 0.85rem 1rem; border-radius: 12px;
  background: var(--green-soft); color: var(--green-dark); font-weight: 700; text-align: center;
}
.toast.show { display: block; }
.toast.error { background: #fdecec; color: var(--danger); }

.hp { position: absolute; left: -9999px; opacity: 0; height: 0; width: 0; }

.footer-note {
  text-align: center; color: var(--muted); font-size: 0.98rem; margin-top: 1.5rem; line-height: 1.8;
}

.hidden { display: none !important; }
.small { font-size: 0.92rem; color: var(--muted); }
code { background: #eef3f0; padding: 0.1rem 0.35rem; border-radius: 4px; }

/* Admin */
.admin-top {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
  gap: 0.75rem; margin-bottom: 1rem;
}
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 1rem;
}
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0.9rem 1rem;
  text-align: center; box-shadow: var(--shadow);
}
.stat strong { display: block; font-size: 2rem; color: var(--blue-dark); line-height: 1.15; }
.stat span { color: var(--muted); font-size: 0.95rem; font-weight: 600; }

.count-note {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
}
.day-count-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}
.day-count-card {
  background: linear-gradient(180deg, #f0f8ff, #fff);
  border: 1px solid #c5e0f5;
  border-radius: 14px;
  padding: 1rem 0.9rem 1.05rem;
  text-align: center;
}
.day-count-num {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--blue-dark);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.day-count-label {
  margin-top: 0.35rem;
  font-weight: 700;
  color: var(--green-dark);
  font-size: 1.02rem;
}
.day-count-sub {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.day-count-bar {
  margin-top: 0.65rem;
  height: 10px;
  background: #e8f0eb;
  border-radius: 999px;
  overflow: hidden;
}
.day-count-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5b9bd5, #3d7eb5);
  border-radius: 999px;
  min-width: 0;
}
@media (max-width: 700px) {
  .day-count-grid { grid-template-columns: 1fr; }
  .day-count-num { font-size: 2.25rem; }
}

table.reg-table {
  width: 100%; border-collapse: collapse; font-size: 0.95rem; background: #fff;
}
table.reg-table th, table.reg-table td {
  border: 1px solid var(--line); padding: 0.55rem 0.6rem; text-align: left; vertical-align: top;
}
table.reg-table th { background: var(--blue-soft); color: var(--blue-dark); }
table.reg-table tr:nth-child(even) td { background: #fafcfb; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.reg-detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  margin-bottom: 0.35rem;
}
.reg-detail-head h2 {
  margin: 0;
}
.sort-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  color: var(--green-dark);
  font-size: 0.98rem;
}
.sort-label select {
  min-height: 42px;
  min-width: 8.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid #c5e0f5;
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

/* Phone cards for 報名明細 — default hidden on wide screens */
.reg-cards { display: none; }
.reg-card {
  background: #fff;
  border: 1px solid #c5e0f5;
  border-radius: 14px;
  padding: 0.95rem 1rem 1.05rem;
  margin: 0 0 0.75rem;
  box-shadow: 0 4px 14px rgba(27, 61, 48, 0.06);
  max-width: 100%;
  overflow: hidden;
  word-break: break-word;
}
.reg-card-empty {
  text-align: center;
  color: var(--muted);
  padding: 1.1rem 0.75rem;
}
.reg-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 0.55rem;
  margin-bottom: 0.25rem;
}
.reg-card-idx {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}
.reg-card-name {
  font-size: 1.2rem;
  color: var(--green-dark);
  font-weight: 800;
}
.reg-card-src {
  font-size: 0.8rem;
  color: var(--blue-dark);
  background: var(--blue-soft);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}
.reg-card-time {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 0.65rem;
}
.reg-card-dl {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.65rem;
}
.reg-card-dl > div {
  min-width: 0;
}
.reg-card-dl .reg-card-full {
  grid-column: 1 / -1;
}
.reg-card-dl dt {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.reg-card-dl dd {
  margin: 0.12rem 0 0;
  font-size: 0.98rem;
  color: var(--text);
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.reg-card-email {
  font-size: 0.92rem !important;
  word-break: break-all;
}
.reg-card-dl a {
  color: var(--blue-dark);
  text-decoration: none;
  font-weight: 700;
}

/* iPhone / small phones only: cards on, table off */
@media (max-width: 699px) {
  .reg-detail-card {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }
  .reg-cards {
    display: block;
  }
  .reg-table-wrap {
    display: none !important;
  }
}

/* iPad / desktop: table on, cards off */
@media (min-width: 700px) {
  .reg-cards {
    display: none !important;
  }
  .reg-table-wrap {
    display: block;
  }
}

.login-box { max-width: 420px; margin: 0 auto 1.5rem; }

.sync-banner {
  background: #fff8e6;
  border: 1px solid #e6c86e;
  color: #6b5200;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  margin: 0 0 1rem;
  line-height: 1.55;
  font-size: 1rem;
}
.sync-banner.hidden { display: none !important; }

/* Edit / delete actions */
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.btn-mini {
  border: 0;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
  touch-action: manipulation;
}
.btn-edit { background: #e8f4fc; color: #3d7eb5; }
.btn-edit:hover { background: #d6ebfa; }
.btn-del { background: #fdecec; color: #b23a3a; }
.btn-del:hover { background: #f8d4d4; }
.reg-card-actions {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top, 1rem));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal.hidden { display: none !important; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 35, 28, 0.45);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  margin: 0.5rem auto 2rem;
  max-height: none;
}
.modal-panel h2 { margin-top: 0; }
body.modal-open { overflow: hidden; }

/* Mobile / iPhone / Android */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  overflow-x: clip;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.btn {
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.choice { min-height: 48px; }
.choice input { width: 1.25rem; height: 1.25rem; }

/* iPad / tablet */
@media (min-width: 700px) and (max-width: 1180px) {
  .wrap, .admin-wrap {
    width: min(920px, calc(100% - 2.5rem));
    padding: 1.75rem 0 3rem;
  }
  .card { padding: 1.45rem 1.5rem 1.55rem; }
  .hero h1 { font-size: clamp(1.75rem, 3.5vw, 2.15rem); }
  .row-2 { grid-template-columns: 1fr 1fr; }
  .actions { justify-content: center; }
  .actions .btn { min-width: 12rem; width: auto; }
  .choice { min-height: 52px; padding: 0.9rem 1rem; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  table.reg-table { font-size: 0.98rem; }
}

@media (max-width: 699px) {
  .wrap, .admin-wrap {
    width: min(920px, calc(100% - 1rem));
    padding: 1rem 0 2.5rem;
  }
  .card {
    padding: 1.1rem 1rem 1.2rem;
    border-radius: 14px;
  }
  .hero h1 { font-size: clamp(1.4rem, 6.5vw, 1.85rem); }
  .hero p, .hero .dates { font-size: 1rem; }
  .row-2 { grid-template-columns: 1fr; gap: 0.65rem; }
  .choice.inline-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
  }
  .actions { flex-direction: column; }
  .actions .btn, .btn { width: 100%; }
  .site-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
  }
  .table-scroll {
    margin: 0 -0.25rem;
    padding-bottom: 0.35rem;
  }
  table.reg-table { font-size: 0.88rem; min-width: 720px; }
  table.reg-table th, table.reg-table td {
    padding: 0.5rem 0.45rem;
    white-space: nowrap;
  }
  table.reg-table td:last-child { white-space: normal; min-width: 8rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .admin-top { flex-direction: column; align-items: stretch; }
  .admin-top .btn { width: 100%; }
}

@media (max-width: 380px) {
  body { font-size: 1rem; }
  .card h2 { font-size: 1.12rem; }
}

/* Any coarse pointer (iPad / Android tablet) */
@media (hover: none) and (pointer: coarse) {
  .choice { min-height: 52px; }
  .btn { min-height: 48px; }
  input, select, textarea { font-size: 16px !important; }
}
