:root {
  --ink: #243029;
  --muted: #667266;
  --paper: #fffdf6;
  --line: rgba(40, 55, 42, 0.16);
  --gold: #c99a3f;
  --rose: #b75468;
  --teal: #2d7d78;
  --leaf: #7fb047;
  --shadow: 0 24px 80px rgba(38, 50, 42, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #10150f;
}

body {
  min-height: 100vh;
  margin: 0;
  color: #fffdf6;
  font-family: "TH Sarabun New", "TH SarabunPSK", "Sarabun", ui-sans-serif, system-ui,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  background: #10150f;
}

body.tree-is-expanded {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 0;
}

.stage {
  position: relative;
  display: grid;
  min-height: 100dvh;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #11180f;
  box-shadow: none;
}

.topbar {
  position: absolute;
  z-index: 12;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  place-items: start center;
  padding: max(16px, env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.event-title {
  position: relative;
  display: grid;
  justify-items: center;
  align-items: start;
  width: min(92vw, 820px);
  padding: 0;
  text-align: center;
  gap: 12px;
}

[data-device="desktop"] .event-title {
  gap: 16px;
}

[data-device="desktop"] .brand-row {
  min-height: 58px;
  padding: 7px 22px 7px 8px;
}

[data-device="desktop"] .school-logo-wrap {
  width: 56px;
}

[data-device="desktop"] .school-name {
  font-size: 1.55rem;
}

[data-device="desktop"] h1 {
  font-size: 4.4rem;
}

[data-device="desktop"] .kicker {
  font-size: 2.05rem;
}

.brand-row {
  display: inline-grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  max-width: min(92vw, 560px);
  min-height: 56px;
  gap: 10px;
  padding: 8px 16px 8px 6px;
  border: 1px solid rgba(255, 245, 205, 0.28);
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(39, 48, 29, 0.62), rgba(109, 76, 34, 0.36)),
    rgba(28, 36, 25, 0.48);
  box-shadow:
    0 12px 30px rgba(9, 13, 9, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
}

.school-logo-wrap {
  display: grid;
  place-items: center;
  width: clamp(38px, 4.4vw, 52px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  box-shadow:
    0 0 0 2px rgba(255, 219, 84, 0.82),
    0 8px 18px rgba(0, 0, 0, 0.2),
    inset 0 0 0 1px rgba(82, 54, 13, 0.18);
}

.school-logo {
  width: 86%;
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
}

.event-title::before {
  content: none;
}

.hero-title {
  display: grid;
  justify-items: center;
  gap: 14px;
  margin-top: 2px;
}

.kicker,
.modal-kicker {
  margin: 0;
  color: #ffd875;
  font-family: "TH Sarabun New", "TH SarabunPSK", "Sarabun", sans-serif;
  font-size: clamp(1.55rem, 2.7vw, 2.15rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1;
  text-shadow:
    0 2px 0 rgba(92, 55, 10, 0.28),
    0 0 18px rgba(255, 218, 113, 0.52);
}

.hero-title .kicker {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 16px;
  background: rgba(39, 48, 29, 0.42);
  box-shadow:
    0 10px 22px rgba(12, 14, 9, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  line-height: 1.12;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  display: block;
  max-width: min(92vw, 680px);
  color: #fff1b4;
  font-family: "TH Sarabun New", "TH SarabunPSK", "Sarabun", serif;
  font-size: clamp(3rem, 5.4vw, 4.25rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: 0;
  -webkit-text-stroke: 1.4px rgba(79, 45, 9, 0.9);
  text-shadow:
    0 2px 0 #5a3410,
    0 4px 0 rgba(81, 48, 16, 0.36),
    0 12px 24px rgba(0, 0, 0, 0.46),
    0 0 18px rgba(255, 221, 122, 0.48);
}

.school-name {
  min-width: 0;
  margin: 0;
  padding: 4px 0;
  color: #ffe7a0;
  font-family: "TH Sarabun New", "TH SarabunPSK", "Sarabun", serif;
  font-size: clamp(1.1rem, 1.7vw, 1.45rem);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.55;
  text-align: left;
  white-space: nowrap;
  -webkit-text-stroke: 0;
  text-shadow:
    0 1px 0 rgba(70, 42, 8, 0.55),
    0 4px 10px rgba(0, 0, 0, 0.32);
}

h1 span {
  position: relative;
  display: inline-block;
}

h1 span::after {
  position: absolute;
  content: "";
  left: 5%;
  right: 7%;
  bottom: 0.02em;
  height: 0.12em;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(255, 238, 173, 0.78), transparent);
  filter: blur(1px);
  opacity: 0.72;
}

.count-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  border-radius: 999px;
  padding: 4px 18px;
  color: #fffdf6;
  background: rgba(183, 84, 104, 0.62);
  box-shadow: 0 8px 24px rgba(20, 18, 12, 0.2);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 800;
  line-height: 1;
}

.ghost-button,
.primary-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.tool-rail {
  position: absolute;
  z-index: 16;
  right: max(14px, env(safe-area-inset-right));
  top: 50%;
  display: grid;
  gap: 12px;
  translate: 0 -50%;
}

.rail-button {
  width: 58px;
  min-height: 58px;
  border: 1px solid rgba(255, 244, 214, 0.34);
  border-radius: 50%;
  color: #fffdf6;
  background:
    radial-gradient(circle at 35% 20%, rgba(255, 255, 255, 0.34), transparent 28%),
    rgba(118, 55, 27, 0.72);
  box-shadow: 0 12px 30px rgba(12, 13, 10, 0.34);
  backdrop-filter: blur(10px);
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1.05;
}

.stage.tree-expanded {
  position: fixed;
  z-index: 30;
  inset: 0;
  min-height: 100dvh;
  border: 0;
  border-radius: 0;
  background: #efe7c9;
  box-shadow: none;
}

.stage.tree-expanded .topbar {
  opacity: 0;
  pointer-events: none;
}

.stage.tree-expanded .tool-rail {
  opacity: 0;
  pointer-events: none;
}

.stage.tree-expanded .tree-stage {
  min-height: 100dvh;
  width: 100vw;
  padding: 0;
}

.stage.tree-expanded .tree-art {
  width: min(100vw, calc(100dvh * 0.6667));
  height: min(100dvh, calc(100vw * 1.5));
  object-fit: contain;
  object-position: center center;
  filter: none;
}

.stage.tree-expanded .leaf-layer {
  left: 50%;
  top: 50%;
  width: min(100vw, calc(100dvh * 0.6667));
  height: min(100dvh, calc(100vw * 1.5));
  transform: translate(-50%, -50%);
  z-index: 8;
}

.stage.tree-expanded .empty-leaves {
  display: none;
}

.return-button {
  position: fixed;
  z-index: 32;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: none;
  min-height: 46px;
  translate: -50% 0;
  border: 1px solid rgba(255, 255, 255, 0.56);
  border-radius: 999px;
  padding: 0 20px;
  color: #fffdf6;
  background: rgba(29, 48, 38, 0.8);
  box-shadow: 0 14px 34px rgba(18, 26, 22, 0.32);
  backdrop-filter: blur(14px);
  font-weight: 850;
}

.stage.tree-expanded .return-button {
  display: none;
  align-items: center;
  justify-content: center;
}

.primary-button {
  width: 100%;
  padding: 0 18px;
  color: #fffdf6;
  background: linear-gradient(135deg, #245a45, #2d7d78 60%, #b6812f);
  box-shadow: 0 12px 26px rgba(34, 92, 72, 0.22);
}

.tree-stage {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
}

.tree-stage::before {
  position: absolute;
  content: "";
  inset: -5%;
  z-index: 0;
  background:
    linear-gradient(180deg, rgba(12, 18, 11, 0.36), rgba(12, 18, 11, 0.18)),
    url("/assets/teacher-tree.png") center center / cover no-repeat;
  filter: blur(22px) saturate(1.18) brightness(0.78);
  transform: scale(1.05);
}

.tree-stage::after {
  position: absolute;
  content: "";
  inset: 0;
  z-index: 2;
  background:
    radial-gradient(circle at 50% 38%, transparent 18%, rgba(13, 22, 14, 0.22) 70%),
    linear-gradient(180deg, rgba(9, 12, 10, 0.42), transparent 24%, transparent 64%, rgba(7, 10, 8, 0.48));
  pointer-events: none;
}

.tree-art {
  width: min(100vw, calc(100dvh * 0.6667));
  height: min(100dvh, calc(100vw * 1.5));
  position: relative;
  z-index: 1;
  object-fit: contain;
  object-position: center center;
  filter: saturate(1.08) contrast(1.03) drop-shadow(0 18px 30px rgba(9, 16, 10, 0.34));
  user-select: none;
}

.leaf-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(100vw, calc(100dvh * 0.6667));
  height: min(100dvh, calc(100vw * 1.5));
  z-index: 5;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.leaf {
  position: absolute;
  width: calc(clamp(24px, 2.8vw, 42px) * var(--scale, 1));
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  color: #213620;
  background: transparent;
  filter: drop-shadow(0 7px 9px rgba(40, 28, 18, 0.3));
  opacity: 0.97;
  transform: translate(-50%, -50%) rotate(var(--rotation));
  pointer-events: auto;
  transition: transform 180ms ease, filter 180ms ease, opacity 180ms ease;
}

.flower-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.flower-petal {
  fill: hsl(var(--flower-hue), 82%, 82%);
  stroke: hsla(calc(var(--flower-hue) - 16), 55%, 48%, 0.38);
  stroke-width: 1.2;
}

.flower-petal.alt {
  fill: hsl(calc(var(--flower-hue) + 12), 86%, 88%);
}

.flower-center {
  fill: #e3a83c;
  stroke: rgba(105, 62, 14, 0.46);
  stroke-width: 1;
}

.leaf:hover,
.leaf:focus-visible {
  filter: brightness(1.12);
  opacity: 1;
  transform: translate(-50%, -50%) rotate(var(--rotation)) scale(calc(var(--scale, 1) * 1.14));
  outline: none;
}

.stage.tree-expanded .leaf {
  width: calc(clamp(32px, 5vw, 58px) * var(--scale, 1));
  filter:
    drop-shadow(0 7px 10px rgba(40, 28, 18, 0.34))
    drop-shadow(0 0 9px hsla(var(--flower-hue), 86%, 76%, 0.34));
  opacity: 1;
}

.empty-leaves {
  margin: 6px 0 0;
  max-width: min(92vw, 460px);
  padding: 8px 14px;
  border-radius: 999px;
  color: #fffdf6;
  font-size: clamp(0.85rem, 1.6vw, 1rem);
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  background: rgba(22, 34, 26, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(10px);
}

.teacher-dock {
  position: absolute;
  z-index: 18;
  left: clamp(12px, 2vw, 24px);
  right: clamp(12px, 2vw, 24px);
  bottom: clamp(12px, 2vw, 24px);
  padding: 14px;
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255, 253, 246, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.52);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 48px rgba(56, 63, 49, 0.2);
  opacity: 0;
  translate: 0 calc(100% + 34px);
  pointer-events: none;
  transition: opacity 180ms ease, translate 220ms ease;
}

.stage.teacher-panel-open .teacher-dock {
  opacity: 1;
  translate: 0 0;
  pointer-events: auto;
}

.stage.tree-expanded .teacher-dock {
  opacity: 0;
  translate: 0 calc(100% + 34px);
  pointer-events: none;
}

.create-button {
  position: fixed;
  z-index: 17;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  min-height: 56px;
  translate: -50% 0;
  border: 1px solid rgba(255, 232, 170, 0.52);
  border-radius: 10px;
  padding: 0 30px;
  color: #fffdf6;
  background: linear-gradient(180deg, #ef8f35, #df5a24);
  box-shadow: 0 16px 36px rgba(68, 26, 8, 0.38);
  font-size: 1.15rem;
  font-weight: 950;
}

.stage.teacher-panel-open .create-button,
.stage.tree-expanded .create-button {
  display: none;
}

.dock-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 12px;
}

.dock-close {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  color: #465347;
  background: rgba(255, 255, 255, 0.7);
  font-weight: 850;
}

.dock-header h2 {
  font-size: clamp(1rem, 2vw, 1.35rem);
}

.dock-header span {
  color: var(--muted);
  white-space: nowrap;
}

.teacher-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(170px, 230px);
  gap: 12px;
  min-height: 98px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.teacher-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-align: left;
  background: rgba(255, 255, 255, 0.58);
}

.teacher-card:hover,
.teacher-card:focus-visible {
  outline: 2px solid rgba(45, 125, 120, 0.32);
  background: rgba(255, 255, 255, 0.86);
}

.teacher-card img,
.modal-photo {
  width: 58px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 8px 16px rgba(31, 42, 34, 0.18);
}

.teacher-name {
  display: block;
  font-weight: 850;
}

.teacher-note {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.modal {
  width: min(92vw, 440px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.modal::backdrop {
  background: rgba(24, 31, 27, 0.44);
  backdrop-filter: blur(8px);
}

.modal-panel {
  position: relative;
  display: grid;
  gap: 14px;
  padding: 26px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 246, 0.98), rgba(247, 244, 231, 0.98));
  box-shadow: var(--shadow);
}

.modal-panel h3 {
  font-size: 1.55rem;
}

.modal-photo {
  width: 74px;
}

.icon-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  font-size: 1.4rem;
  line-height: 1;
}

label {
  display: grid;
  gap: 7px;
  color: #3f4c43;
  font-size: 0.92rem;
  font-weight: 750;
}

input,
textarea {
  width: 100%;
  border: 1px solid rgba(45, 72, 50, 0.2);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
}

textarea {
  resize: vertical;
}

.read-panel blockquote {
  margin: 0;
  color: #26372d;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 850;
  line-height: 1.38;
}

.signature {
  margin: 0;
  color: var(--rose);
  font-weight: 800;
}

.fineprint {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.form-status {
  min-height: 1.2em;
  margin: -4px 0 0;
  color: #8c3042;
  font-size: 0.9rem;
  font-weight: 750;
}

.admin-teachers {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-top: 4px;
}

.admin-section-title {
  margin-top: 8px;
  font-size: 1rem;
}

.admin-messages {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding-top: 4px;
}

.admin-message-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.admin-message-body {
  display: block;
  color: var(--ink);
  font-weight: 750;
  line-height: 1.35;
}

.admin-teacher-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.52);
}

.admin-teacher-row img {
  width: 42px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
}

.danger-button {
  min-height: 36px;
  border: 1px solid rgba(183, 84, 104, 0.3);
  border-radius: 8px;
  color: #8c3042;
  background: rgba(183, 84, 104, 0.08);
  font-weight: 800;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 22px;
  max-width: min(90vw, 460px);
  padding: 12px 16px;
  border-radius: 8px;
  color: #fffdf6;
  background: rgba(35, 54, 44, 0.94);
  box-shadow: 0 12px 28px rgba(20, 28, 24, 0.26);
  opacity: 0;
  translate: -50% 14px;
  transition: opacity 180ms ease, translate 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  translate: -50% 0;
}

@media (max-width: 720px) {
  .app-shell {
    padding: 0;
  }

  .stage {
    min-height: 100vh;
    border-radius: 0;
  }

  .topbar {
    padding: max(10px, env(safe-area-inset-top)) 12px 0;
  }

  h1 {
    max-width: calc(100vw - 48px);
    font-size: clamp(1.85rem, 8.4vw, 2.55rem);
    line-height: 1.08;
  }

  .kicker {
    font-size: clamp(0.95rem, 3.8vw, 1.2rem);
  }

  .hero-title {
    gap: 10px;
    margin-top: 2px;
  }

  .hero-title .kicker {
    min-height: 30px;
    padding: 0 12px;
  }

  .school-name {
    overflow: hidden;
    font-size: clamp(0.82rem, 3vw, 1rem);
    text-align: left;
    text-overflow: ellipsis;
  }

  .event-title {
    width: calc(100vw - 48px);
    padding: 0;
    gap: 8px;
  }

  .brand-row {
    max-width: calc(100vw - 48px);
    min-height: 48px;
    gap: 8px;
    padding: 7px 14px 7px 6px;
  }

  .school-logo-wrap {
    width: clamp(30px, 8.4vw, 38px);
  }

  .count-pill {
    min-height: 30px;
    padding: 4px 15px;
    font-size: clamp(1rem, 4.5vw, 1.2rem);
  }

  .tool-rail {
    right: max(10px, env(safe-area-inset-right));
    gap: 9px;
  }

  .rail-button {
    width: 50px;
    min-height: 50px;
    font-size: 0.68rem;
  }

  .tree-stage {
    min-height: 100dvh;
    padding: 0;
  }

  .tree-art,
  .stage.tree-expanded .tree-art {
    width: min(100vw, calc(100dvh * 0.6667));
    height: min(100dvh, calc(100vw * 1.5));
    object-position: center center;
  }

  .leaf-layer {
    left: 50%;
    top: 50%;
    width: min(100vw, calc(100dvh * 0.6667));
    height: min(100dvh, calc(100vw * 1.5));
  }

  .empty-leaves {
    font-size: 0.85rem;
    padding: 6px 12px;
  }

  .teacher-list {
    grid-auto-columns: minmax(158px, 78vw);
  }

  .teacher-dock {
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    max-height: 42vh;
    overflow: auto;
  }

  .create-button {
    min-height: 52px;
    padding: 0 24px;
  }
}
