:root {
  --bg: #fff3d8;
  --paper: rgba(255, 251, 244, 0.94);
  --card: #fffdf8;
  --ink: #2c2416;
  --muted: #7d6b52;
  --line: #f0e0c4;
  --yellow: #ffc83d;
  --yellow-deep: #f0a202;
  --navy: #243e78;
  --sky: #d7ecfb;
  --blush: #ffd0c2;
  --danger: #b42318;
  --ok: #237a45;
  --shadow: 0 12px 30px rgba(36, 62, 120, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; touch-action: manipulation; }

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

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: clip;
}

body {
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background:
    radial-gradient(circle at 8% 0%, rgba(255, 200, 61, 0.55), transparent 26%),
    radial-gradient(circle at 100% 8%, rgba(215, 236, 251, 0.95), transparent 28%),
    var(--bg);
}

body.sheet-open { overflow: hidden; }

button { font: inherit; color: inherit; }

input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

a { color: var(--navy); }

img { max-width: 100%; }

:focus-visible {
  outline: 3px solid rgba(36, 62, 120, 0.35);
  outline-offset: 2px;
}

.shell {
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8), 0 24px 60px rgba(36, 62, 120, 0.08);
}

.frame { min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: rgba(255, 246, 226, 0.92);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.brand img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  box-shadow: var(--shadow);
}

.brand h1,
.brand p,
.hero h1,
.lead,
.hint,
.note,
.field-error,
.status-line,
.summary-line {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p,
.hint,
.note,
.who,
.summary span,
.field span,
.choice span {
  color: var(--muted);
}

.brand p { font-size: 12px; }

.wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
}

.welcome .hero {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(28px + env(safe-area-inset-top)) 22px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}

.hero-logo {
  width: 168px;
  height: 168px;
  margin: 0 auto 8px;
  border-radius: 50%;
  background: white;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--yellow-deep);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  font-size: 40px;
  line-height: 1.1;
}

.lead {
  margin-top: 10px;
  font-size: 16px;
  line-height: 1.6;
}

.stack { display: flex; flex-direction: column; gap: 12px; }

.stack .lead { margin-top: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.btn-block { width: 100%; }

.btn-primary {
  background: var(--yellow);
  color: var(--navy);
  box-shadow: 0 8px 0 #e0ac12;
}

.btn-primary:active { transform: translateY(2px); box-shadow: 0 4px 0 #e0ac12; }

.btn-ghost {
  background: white;
  color: var(--navy);
  box-shadow: inset 0 0 0 1.5px var(--line);
}

.btn:disabled,
.choice:disabled,
.chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.icon-btn,
.text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  color: var(--navy);
  text-decoration: none;
  font-weight: 700;
}

.text-link {
  display: inline-flex;
  justify-content: center;
  min-height: 44px;
  align-items: center;
  font-weight: 700;
  text-decoration: none;
}

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }

.field.beside {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.field.beside > span {
  flex: none;
  white-space: nowrap;
}

.field input,
.field select {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: white;
  font-size: 16px;
  font-weight: 500;
}

.field input {
  appearance: none;
  -webkit-appearance: none;
}

.field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23243e78' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
}

.field.beside select {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
}

.field input.fit {
  width: 12.5rem;
  max-width: calc(100% - 4.5rem);
  flex: none;
}

.field input.num {
  width: 6.5rem;
  flex: none;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.field-error,
.alert {
  color: var(--danger);
  font-size: 14px;
  line-height: 1.5;
}

.field-error:empty { display: none; }

.alert {
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff1ee;
}

.alert[hidden] { display: none; }

.status-line { min-height: 1.4em; color: var(--muted); }

.hint { font-size: 13px; line-height: 1.5; }

.success { text-align: center; padding-top: 12px; }

.success h2 { margin: 0; font-size: 28px; }

.success-mark {
  width: 64px;
  height: 64px;
  margin: 8px auto 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--yellow);
  color: var(--navy);
  font-size: 32px;
  font-weight: 800;
}

.name-list {
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.name-list li {
  padding: 12px 14px;
  border-radius: 14px;
  background: white;
  box-shadow: inset 0 0 0 1px var(--line);
}

.who-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.who {
  margin: 0;
  font-size: 13px;
  word-break: break-all;
}

.admin-entry {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 16px;
  background: var(--navy);
  color: white;
  font-weight: 700;
  text-decoration: none;
}

.course-card,
.log-card,
.summary,
.empty {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.course-card { padding: 8px; display: flex; flex-direction: column; gap: 8px; }

.course-card > .btn {
  width: auto;
  margin-inline: 12px;
}

.course-open {
  display: block;
  width: 100%;
  padding: 12px 12px 4px;
  text-align: left;
  border-radius: 18px;
}

.course-open h2,
.empty h2,
.sheet-head h2 { margin: 0; }

.course-open h2 { font-size: 22px; }

.note { margin-top: 4px; font-size: 14px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
}

.stat {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  box-sizing: border-box;
  min-height: 58px;
  margin: 0;
  padding: 10px 8px 16px;
  border-radius: 16px;
  background: #fff6df;
  white-space: nowrap;
}

.summary div {
  padding: 0;
  text-align: center;
}

.stat b,
.summary b {
  color: var(--navy);
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat b.inf {
  font-size: 40px;
  line-height: 0.7;
}

.summary b {
  display: block;
  font-size: 18px;
  line-height: 1.15;
}

.stat span,
.summary span { font-size: 12px; }

.stat span {
  font-weight: 700;
  color: var(--muted);
  line-height: 1;
}

.stat.over b { color: var(--danger); }

.bar {
  height: 8px;
  margin: 10px 2px 0;
  border-radius: 999px;
  background: #fff1cc;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--yellow), var(--navy));
}

.skeleton {
  height: 164px;
  border-radius: 24px;
  background: linear-gradient(90deg, #fff, #ffe7a8, #fff);
  background-size: 200% 100%;
  animation: shine 1.2s ease infinite;
}

@keyframes shine {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

.empty {
  padding: 28px 18px;
  text-align: center;
}

.empty img {
  width: 96px;
  height: 96px;
  margin: 0 auto 8px;
  border-radius: 50%;
}

.empty p { color: var(--muted); line-height: 1.6; }

.month-nav {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
}

.month-nav strong { text-align: center; font-size: 18px; }

.weekdays,
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }

.weekdays { margin-top: 4px; }

.weekdays span {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.day {
  aspect-ratio: 1;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
}

.day.spacer { pointer-events: none; }

.day .num { font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }

.day .hours {
  min-height: 16px;
  font-size: 11px;
  font-weight: 800;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.day.has { background: white; box-shadow: inset 0 0 0 1px var(--line); }

.day.has .hours {
  padding: 0 5px;
  border-radius: 999px;
  background: var(--sky);
}

.day.is-today { box-shadow: inset 0 0 0 2px var(--navy); }

.day.is-selected { background: var(--yellow); }

.day.is-selected.has .hours { background: white; }

.sheet-root { position: fixed; inset: 0; z-index: 20; }

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(44, 36, 22, 0.38);
}

.sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(100%, 480px);
  max-height: min(92dvh, 820px);
  overflow: auto;
  overscroll-behavior: contain;
  transform: translateX(-50%) translateY(var(--sheet-y, 0px));
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: #fffaf0;
  box-shadow: 0 -12px 40px rgba(36, 62, 120, 0.16);
  transition: transform 0.22s ease;
}

.sheet-root.is-dragging .sheet,
.sheet-root.is-dragging .sheet-mask { transition: none; }

.sheet-mask { transition: opacity 0.22s ease; }

.sheet-grab {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  min-height: 48px;
  margin: 0 -16px 8px;
  padding: 8px 8px 10px;
  background: #fffaf0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.sheet-handle {
  grid-column: 2;
  width: 56px;
  height: 6px;
  margin: 0 auto;
  border-radius: 999px;
  background: #e4d0aa;
}

.sheet-close {
  grid-column: 3;
  justify-self: end;
  min-width: 44px;
  min-height: 44px;
  padding: 0 6px;
  color: var(--navy);
  font-size: 16px;
  font-weight: 700;
}

.sheet-head { margin-bottom: 8px; }

.sheet-head h2 { font-size: 24px; line-height: 1.3; }

.sheet-head h2.sheet-title {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1;
}

.sheet-quota {
  color: var(--navy);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.remain { margin: 4px 0 0; color: var(--navy); font-weight: 700; }

.picked {
  display: flex;
  align-items: center;
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 18px;
  background: white;
}

.picked-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tag-recorded {
  padding: 2px 8px;
  border: 1.5px solid var(--danger);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}

.picked-line strong {
  font-size: 22px;
  line-height: 1.2;
  white-space: nowrap;
}

.picked-line span {
  white-space: nowrap;
  font-weight: 700;
}

.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.choice {
  min-height: 84px;
  border-radius: 20px;
  background: var(--yellow);
  color: var(--navy);
  box-shadow: 0 6px 0 #e0ac12;
}

.choice strong { display: block; font-size: 32px; line-height: 1; }

.choice:active:not(:disabled) { transform: translateY(2px); }

.log-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.log-card { padding: 14px; display: flex; flex-direction: column; gap: 8px; }

.log-card p { margin: 0; word-break: break-all; }

.log-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--blush);
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.editor { display: flex; flex-direction: column; gap: 8px; }

.editor-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-line .field.beside {
  flex: 1;
  min-width: 0;
  gap: 6px;
}

.editor-line .field input.num {
  width: 4.25rem;
  min-height: 44px;
  padding: 0 8px;
}

.chips { display: flex; gap: 8px; }

.chip {
  width: 40px;
  height: 44px;
  border-radius: 14px;
  background: white;
  box-shadow: inset 0 0 0 1.5px var(--line);
  font-weight: 800;
}

.chip.on { background: var(--navy); color: white; }

.summary-line { font-weight: 700; color: var(--navy); }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--navy);
  color: white;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .toast,
  .sheet,
  .sheet-mask { transition: none; }
}
