:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --ink: #1f2530;
  --ink-soft: #5f6b7d;
  --line: #dbe2ec;
  --accent: #0f766e;
  --accent-strong: #0a5e59;
  --warning: #b45309;
  --shadow: 0 14px 30px rgba(31, 37, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", sans-serif;
  background: radial-gradient(circle at 20% 10%, #fcefd8 0%, transparent 30%),
    radial-gradient(circle at 80% 20%, #d8f3ff 0%, transparent 38%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

body.gate-active {
  overflow: hidden;
}

body:not(.admin-mode) .admin-only {
  display: none;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(42px);
  opacity: 0.38;
  pointer-events: none;
  z-index: -1;
}

.orb-a {
  width: 280px;
  height: 280px;
  background: #f59e0b;
  top: -80px;
  left: -60px;
}

.orb-b {
  width: 360px;
  height: 360px;
  background: #14b8a6;
  bottom: -120px;
  right: -90px;
}

.page {
  width: min(1240px, 96vw);
  margin: 24px auto 56px;
  display: grid;
  gap: 16px;
}

.app-shell {
  display: grid;
}

body.gate-active .app-shell {
  display: none;
}

.adventure-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 16px;
}

body.gate-active .adventure-gate {
  display: grid;
}

.gate-intro-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.92;
  filter: saturate(0.92) contrast(1.03) brightness(0.78);
  z-index: 0;
}

.adventure-gate.video-fadeout .gate-intro-video {
  opacity: 0;
}

.gate-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(245, 158, 11, 0.22), transparent 35%),
    radial-gradient(circle at 80% 18%, rgba(20, 184, 166, 0.2), transparent 40%),
    linear-gradient(145deg, #0d1326 0%, #111827 48%, #121826 100%);
  z-index: 1;
  opacity: 0;
  transition: opacity 3.2s ease;
}

.adventure-gate.video-fadeout .gate-backdrop {
  opacity: 1;
}

.gate-panel {
  position: relative;
  width: min(980px, 95vw);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 22px;
  padding: 22px;
  color: #e2e8f0;
  background:
    linear-gradient(160deg, rgba(15, 23, 42, 0.9) 0%, rgba(30, 41, 59, 0.88) 55%, rgba(15, 23, 42, 0.92) 100%),
    repeating-linear-gradient(120deg, transparent 0 16px, rgba(148, 163, 184, 0.05) 16px 17px);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: 2;
}

.gate-kicker {
  margin: 0;
  color: #f8fafc;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.74rem;
  font-family: "Cinzel", "Noto Serif SC", serif;
}

.gate-panel h1 {
  margin: 8px 0 8px;
  font-size: clamp(1.7rem, 3.2vw, 2.4rem);
  color: #fef3c7;
  font-family: "Cinzel", "Noto Serif SC", serif;
}

.gate-subtitle {
  margin: 0 0 14px;
  color: #cbd5e1;
  line-height: 1.5;
}

.gate-status {
  margin-bottom: 12px;
}

.gate-identity-grid {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
}

.gate-identity-grid label {
  color: #cbd5e1;
}

.gate-identity-grid input,
.gate-identity-grid select {
  background: rgba(255, 255, 255, 0.96);
}

.username-login-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.username-login-inline input {
  flex: 1;
}

.username-login-inline .btn {
  white-space: nowrap;
}

.gate-group-select {
  grid-column: 1 / -1;
}

.group-select-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.group-select-actions .btn {
  min-width: 120px;
}

.admin-mode-block {
  margin-top: -2px;
}

.admin-mode-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.admin-mode-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #e2e8f0;
  font-size: 0.9rem;
}

.admin-mode-toggle-label input {
  margin: 0;
}

.gate-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.gate-hint {
  color: #cbd5e1;
}

.card {
  background: color-mix(in srgb, var(--card) 94%, #f2f6fb 6%);
  border: 1px solid color-mix(in srgb, var(--line) 75%, transparent 25%);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: rise-in 460ms ease both;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero h1,
h2,
h3,
.eyebrow {
  font-family: "Bricolage Grotesque", sans-serif;
  margin: 0;
}

.eyebrow {
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.subtitle {
  margin: 10px 0 12px;
  color: var(--ink-soft);
  line-height: 1.45;
}

.status {
  display: inline-flex;
  align-items: center;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.9rem;
}

.section-title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.identity-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 14px rgba(17, 24, 39, 0.08);
}

.btn:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn.primary {
  background: linear-gradient(130deg, var(--accent) 0%, #14b8a6 100%);
  border-color: transparent;
  color: white;
}

.btn.primary:hover {
  background: linear-gradient(130deg, var(--accent-strong) 0%, #0ea5a2 100%);
}

.btn.ghost {
  background: #f9fafb;
}

.btn.danger {
  background: #fff1f2;
  color: #be123c;
  border-color: #fecdd3;
}

.btn.danger:hover {
  background: #ffe4e6;
}

.metric {
  color: #065f46;
  font-weight: 600;
}

.toolbar,
.view-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 10px;
}

.preset-select-label {
  min-width: 220px;
}

.preset-select-label select {
  min-width: 220px;
}

.hint {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.help-list {
  margin: 0;
  padding-left: 20px;
  color: #334155;
  display: grid;
  gap: 6px;
}

.help-list li {
  line-height: 1.4;
}

.multi-group-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: #fcfdff;
}

.multi-group-box summary {
  cursor: pointer;
  color: #334155;
  font-weight: 600;
}

.sync-groups {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.group-multi-select {
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  max-height: 140px;
  overflow: auto;
}

.group-select-block {
  align-items: start;
}

.sync-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  color: #374151;
  font-size: 0.86rem;
}

.sync-item input {
  margin: 0;
}

.schedule-grid {
  display: grid;
  grid-template-columns: 72px repeat(7, minmax(90px, 1fr));
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: 64vh;
  background: #fbfdff;
  position: relative;
}

.range-highlight-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  pointer-events: none;
}

.slot-range-highlight {
  position: absolute;
  border: 2px solid #f59e0b;
  border-radius: 9px;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0.09) 40%, rgba(255, 255, 255, 0.03) 100%),
    radial-gradient(140% 48% at 50% 0%, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
}

.slot-range-highlight::before,
.slot-range-highlight::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

.slot-range-highlight::before {
  top: 0;
  height: 34%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.34) 0%, rgba(255, 255, 255, 0.08) 100%);
}

.slot-range-highlight::after {
  bottom: 0;
  height: 42%;
  background: linear-gradient(0deg, rgba(2, 6, 23, 0.12) 0%, transparent 100%);
}

.slot-range-marker {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 14px;
  padding: 0 4px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.84);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
}

.grid-head,
.time-cell,
.day-cell,
.slot-cell {
  border-bottom: 1px solid #edf2f7;
  border-right: 1px solid #edf2f7;
}

.grid-head,
.day-cell {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fbff;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
  padding: 8px 4px;
}

.time-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fcfdff;
  font-size: 0.76rem;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot-cell {
  min-height: 24px;
  background: white;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: filter 0.1s ease;
}

.slot-cell:hover {
  filter: brightness(0.95);
}

.slot-cell.available {
  background: color-mix(in srgb, var(--accent) 66%, #fff 34%);
}

.slot-cell.muted {
  filter: saturate(0.3) brightness(1.06);
}

.slot-cell.optimal {
  outline: 2px solid #f59e0b;
  outline-offset: -2px;
}

.slot-cell.no-conflict {
  box-shadow: inset 0 0 0 2px #0e9f6e;
}

.slot-cell.group-optimal {
  outline: none;
}

.slot-cell.range-covered {
  border-color: transparent !important;
}

.slot-cell.range-covered-top {
  border-top-left-radius: 9px;
  border-top-right-radius: 9px;
}

.slot-cell.range-covered-bottom {
  border-bottom-left-radius: 9px;
  border-bottom-right-radius: 9px;
}

.slot-markers {
  position: absolute;
  top: 2px;
  right: 2px;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 2px;
  max-width: calc(100% - 4px);
  pointer-events: none;
}

.slot-marker {
  min-width: 14px;
  height: 12px;
  padding: 0 3px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.84);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
}

.slot-cell::after {
  display: none;
}

.hidden-row {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  font-size: 0.85rem;
  position: relative;
  cursor: help;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-tooltip {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-4px);
  min-width: 180px;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
  color: #0f172a;
  font-size: 0.78rem;
  line-height: 1.4;
  white-space: pre-line;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.legend-item:hover .legend-tooltip,
.legend-item:focus-within .legend-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.recommend-wrap {
  margin-top: 12px;
}

.recommend-list {
  margin: 8px 0 0;
  padding-left: 24px;
  display: grid;
  gap: 6px;
}

.recommend-list li {
  color: #374151;
  line-height: 1.4;
}

.recommend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.manage-members {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fbfdff;
}

.member-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.7fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #edf2f7;
}

.member-row:last-child {
  border-bottom: none;
}

.member-meta {
  color: #64748b;
  font-size: 0.85rem;
}

.member-badge {
  justify-self: start;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  border: 1px solid #dbeafe;
  color: #1d4ed8;
  background: #eff6ff;
}

.member-empty {
  color: #64748b;
  padding: 12px;
}

dialog {
  border: none;
  border-radius: 14px;
  box-shadow: 0 24px 44px rgba(15, 23, 42, 0.28);
  padding: 0;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.25);
}

.dialog-inner {
  min-width: min(450px, 90vw);
  padding: 18px;
  display: grid;
  gap: 10px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.save-confirm-inner {
  min-width: min(560px, 92vw);
}

.confirm-grid {
  display: grid;
  gap: 8px;
}

.confirm-item {
  border: 1px solid #dbeafe;
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.confirm-item span {
  font-size: 0.82rem;
  color: #475569;
}

.confirm-item strong {
  color: #0f172a;
  font-size: 1.02rem;
  line-height: 1.4;
}

body:not(.gate-active) {
  background:
    radial-gradient(circle at 12% 14%, rgba(245, 158, 11, 0.18), transparent 34%),
    radial-gradient(circle at 84% 20%, rgba(20, 184, 166, 0.16), transparent 40%),
    linear-gradient(145deg, #0b1222 0%, #101827 50%, #121a2a 100%);
  color: #e5edf8;
}

body:not(.gate-active) .bg-orb {
  opacity: 0.18;
  filter: blur(56px);
}

body:not(.gate-active) .card {
  background:
    linear-gradient(160deg, rgba(15, 23, 42, 0.86) 0%, rgba(30, 41, 59, 0.8) 55%, rgba(17, 24, 39, 0.86) 100%),
    repeating-linear-gradient(120deg, transparent 0 18px, rgba(148, 163, 184, 0.05) 18px 19px);
  border-color: rgba(148, 163, 184, 0.4);
  box-shadow: 0 18px 34px rgba(2, 6, 23, 0.45);
}

body:not(.gate-active) .eyebrow,
body:not(.gate-active) .subtitle,
body:not(.gate-active) .hint,
body:not(.gate-active) label,
body:not(.gate-active) .help-list li,
body:not(.gate-active) .recommend-list li,
body:not(.gate-active) .member-meta,
body:not(.gate-active) .member-empty {
  color: #cbd5e1;
}

body:not(.gate-active) h1,
body:not(.gate-active) h2,
body:not(.gate-active) h3 {
  color: #f8fafc;
}

body:not(.gate-active) input,
body:not(.gate-active) select {
  background: rgba(15, 23, 42, 0.65);
  color: #e2e8f0;
  border-color: rgba(148, 163, 184, 0.45);
}

body:not(.gate-active) input::placeholder {
  color: #94a3b8;
}

body:not(.gate-active) .btn {
  background: rgba(30, 41, 59, 0.78);
  color: #e2e8f0;
  border-color: rgba(148, 163, 184, 0.45);
}

body:not(.gate-active) .btn.ghost {
  background: rgba(15, 23, 42, 0.58);
}

body:not(.gate-active) .btn.primary {
  background: linear-gradient(130deg, #0f766e 0%, #14b8a6 100%);
}

body:not(.gate-active) .btn.danger {
  background: rgba(190, 24, 93, 0.2);
  color: #fecdd3;
  border-color: rgba(251, 113, 133, 0.42);
}

body:not(.gate-active) .sync-item,
body:not(.gate-active) .legend-item {
  background: rgba(15, 23, 42, 0.62);
  border-color: rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
}

body:not(.gate-active) .group-multi-select,
body:not(.gate-active) .manage-members,
body:not(.gate-active) .schedule-grid {
  background: rgba(15, 23, 42, 0.62);
  border-color: rgba(148, 163, 184, 0.36);
}

body:not(.gate-active) .grid-head,
body:not(.gate-active) .day-cell {
  background: rgba(30, 41, 59, 0.88);
  color: #f1f5f9;
}

body:not(.gate-active) .time-cell {
  background: rgba(30, 41, 59, 0.84);
  color: #cbd5e1;
}

body:not(.gate-active) .slot-cell {
  background: rgba(15, 23, 42, 0.42);
}

body:not(.gate-active) .slot-range-highlight {
  background:
    linear-gradient(180deg, rgba(56, 189, 248, 0.14) 0%, rgba(99, 102, 241, 0.08) 42%, rgba(15, 23, 42, 0.04) 100%),
    radial-gradient(140% 48% at 50% 0%, rgba(148, 163, 184, 0.22) 0%, transparent 70%);
}

body:not(.gate-active) .slot-range-highlight::before {
  background: linear-gradient(180deg, rgba(226, 232, 240, 0.22) 0%, rgba(226, 232, 240, 0.05) 100%);
}

body:not(.gate-active) .slot-range-highlight::after {
  background: linear-gradient(0deg, rgba(2, 6, 23, 0.26) 0%, transparent 100%);
}

body:not(.gate-active) #edit-grid .slot-cell.available {
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.64) 0%, rgba(14, 165, 233, 0.56) 100%);
  box-shadow: inset 0 0 0 1px rgba(153, 246, 228, 0.92);
}

body:not(.gate-active) #edit-grid .slot-cell.available:hover {
  filter: brightness(1.08);
}

body:not(.gate-active) .grid-head,
body:not(.gate-active) .time-cell,
body:not(.gate-active) .day-cell,
body:not(.gate-active) .slot-cell,
body:not(.gate-active) .member-row {
  border-color: rgba(148, 163, 184, 0.25);
}

body:not(.gate-active) .legend-tooltip {
  border-color: rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.94);
  color: #e2e8f0;
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.55);
}

body:not(.gate-active) dialog {
  background: rgba(15, 23, 42, 0.96);
}

body:not(.gate-active) .confirm-item {
  border-color: rgba(148, 163, 184, 0.45);
  background: rgba(30, 41, 59, 0.8);
}

body:not(.gate-active) .confirm-item span {
  color: #cbd5e1;
}

body:not(.gate-active) .confirm-item strong {
  color: #f8fafc;
}

@media (max-width: 980px) {
  .gate-panel {
    width: min(100%, 96vw);
    padding: 18px;
  }

  .gate-identity-grid {
    grid-template-columns: 1fr 1fr;
  }

  .admin-mode-row {
    width: 100%;
  }

  .identity-grid {
    grid-template-columns: 1fr 1fr;
  }

  .schedule-grid {
    grid-template-columns: 56px repeat(7, minmax(76px, 1fr));
  }

  .member-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media (max-width: 640px) {
  .gate-panel {
    border-radius: 16px;
    padding: 14px;
  }

  .gate-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .gate-actions .btn {
    width: 100%;
  }

  .page {
    width: min(100vw, 100%);
    margin: 0;
    padding: 10px;
  }

  .card {
    border-radius: 14px;
    padding: 14px;
  }

  .identity-grid {
    grid-template-columns: 1fr;
  }

  .schedule-grid {
    grid-template-columns: 52px repeat(7, minmax(58px, 1fr));
    max-height: 56vh;
  }

  .slot-cell::after {
    display: none;
  }
}
