:root {
  --bg: #f3f6f4;
  --bg-elevated: #ffffff;
  --surface: #e8f0eb;
  --text: #14201a;
  --text-muted: #4d5f56;
  --brand: #0f6b4c;
  --brand-strong: #0a4f38;
  --accent: #c45c26;
  --border: #c5d4cb;
  --focus: #1a7a56;
  --danger: #b42318;
  --success: #067647;
  --warning: #b54708;
  --shadow: 0 12px 40px rgba(20, 32, 26, 0.08);
  --radius: 18px;
  --font-sans: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  --font-display: "Outfit", "Pretendard", sans-serif;
  --space: clamp(1rem, 2vw, 1.5rem);
  --max: 1120px;
  --touch: 44px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f1612;
  --bg-elevated: #18211c;
  --surface: #223028;
  --text: #e8f2ec;
  --text-muted: #9fb0a6;
  --brand: #3dba86;
  --brand-strong: #62d4a2;
  --accent: #e0894f;
  --border: #2f4137;
  --focus: #62d4a2;
  --danger: #f97066;
  --success: #47cd89;
  --warning: #fdb022;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15, 107, 76, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(196, 92, 38, 0.10), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

img { max-width: 100%; height: auto; }
a { color: var(--brand-strong); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--brand);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 1000;
}
.skip-link:focus { left: 1rem; top: 1rem; }

.container {
  width: min(100% - 2rem, var(--max));
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
}
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.brand span { color: var(--brand); }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.nav a, .nav button {
  min-height: var(--touch);
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.nav a:hover, .nav button:hover {
  background: var(--surface);
  border-color: var(--border);
}

.site-main { padding: 2rem 0 4rem; }
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0 3rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.footer-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .footer-grid { grid-template-columns: 2fr 1fr 1fr; }
}

h1, h2, h3 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
  line-height: 1.25;
  margin: 0 0 0.75rem;
}
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 3vw, 1.8rem); }
.lead { font-size: 1.05rem; color: var(--text-muted); max-width: 42rem; }

.hero {
  padding: 1.5rem 0 2.5rem;
  animation: rise 0.6s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.tool-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .tool-grid { grid-template-columns: repeat(3, 1fr); }
}

.tool-link {
  display: block;
  padding: 1.25rem 1.35rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, border-color 0.2s ease;
  min-height: 7.5rem;
}
.tool-link:hover {
  transform: translateY(-3px);
  border-color: var(--brand);
}
.tool-link h2,
.tool-link h3 { font-size: 1.2rem; margin-bottom: 0.35rem; }

.seo-columns {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .seo-columns { grid-template-columns: repeat(3, 1fr); }
}
.seo-columns h3 { font-size: 1.05rem; margin-bottom: 0.5rem; }

.faq-list dt {
  font-weight: 600;
  margin-top: 1rem;
}
.faq-list dt:first-child { margin-top: 0; }
.faq-list dd {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
}

.seo-related { margin-top: 0.75rem; }
.tool-link p { margin: 0; color: var(--text-muted); }

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.stack { display: grid; gap: 1rem; }
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}
.row.row-end { align-items: end; }
/* .stack/.row의 display가 [hidden]을 덮어쓰지 않도록 */
.stack[hidden],
.row[hidden],
.room-mode-options[hidden],
#roomModeOptions[hidden] {
  display: none !important;
}

/* 기본: 라벨 위 / 입력 아래 */
label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 0;
}
/* 체크박스·라디오: 한 줄로 정렬 */
label.check,
label:has(> input[type="checkbox"]),
label:has(> input[type="radio"]) {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: auto;
  max-width: 100%;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
}
label.file-field {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  width: auto;
  max-width: 100%;
  font-weight: 500;
}

input, textarea, select, button, .btn {
  font: inherit;
}
input, textarea, select {
  width: 100%;
  min-height: var(--touch);
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input[type="checkbox"],
input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  min-width: 1.15rem;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--brand);
  border-radius: 4px;
  cursor: pointer;
}
input[type="file"] {
  width: auto;
  max-width: 100%;
  min-height: var(--touch);
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
}
textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.5;
}

.field-grow { flex: 1 1 12rem; min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0.65rem 1.1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 650;
  text-decoration: none;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-strong); color: #fff; }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.breadcrumbs li:not(:last-child)::after {
  content: "/";
  margin-left: 0.35rem;
  opacity: 0.6;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.status::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: currentColor;
}
.status-loading { color: var(--warning); background: color-mix(in srgb, var(--warning) 15%, transparent); }
.status-success { color: var(--success); background: color-mix(in srgb, var(--success) 15%, transparent); }
.status-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 15%, transparent); }
.status-empty { color: var(--text-muted); background: var(--surface); }

.sr-only,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.alert-error { border-color: var(--danger); color: var(--danger); }
.alert-success { border-color: var(--success); color: var(--success); }

.tips { color: var(--text-muted); }
.tips li { margin-bottom: 0.35rem; }

.result-block {
  margin-top: 1rem;
  scroll-margin-bottom: 40vh;
}
.team-card, .order-item {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  margin-bottom: 0.6rem;
}
.seat-grid {
  display: grid;
  gap: 0.35rem;
  overflow-x: auto;
}
.seat {
  min-height: 2.5rem;
  min-width: 4.5rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  padding: 0.25rem;
}
.seat.filled {
  border-style: solid;
  background: color-mix(in srgb, var(--brand) 18%, var(--bg-elevated));
}
.seat.blocked {
  background: repeating-linear-gradient(45deg, var(--surface), var(--surface) 4px, transparent 4px, transparent 8px);
  color: var(--text-muted);
}

.ad-slot {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 1.5rem 0;
  min-height: 100px;
  box-sizing: border-box;
  color: var(--text-muted);
  font-size: 0.85rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.ad-slot[hidden] { display: none !important; }
.ad-slot.is-live {
  border: none;
  background: transparent;
  min-height: 100px;
  overflow: visible;
}
.ad-slot.is-live .adsbygoogle {
  display: block !important;
  width: 100% !important;
  min-height: 100px;
  max-width: 100%;
}
.ad-slot .ad-placeholder {
  display: grid;
  place-items: center;
  min-height: 100px;
  padding: 1rem;
  text-align: center;
}

.visually-quiet { color: var(--text-muted); font-size: 0.9rem; }

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 280px;
  overflow-y: auto;
  padding: 0.85rem;
  margin: 0.75rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 140px;
}
.chat-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: auto;
  text-align: center;
}
.chat-item {
  display: grid;
  gap: 0.15rem;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, var(--brand));
}
.chat-item.is-mine {
  background: color-mix(in srgb, var(--brand) 16%, var(--bg-elevated));
}
.chat-item.is-system {
  background: transparent;
  padding: 0.15rem 0.35rem;
  text-align: center;
}
.chat-system-body {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.chat-system-body time {
  margin-left: 0.35rem;
  opacity: 0.8;
}
.chat-meta {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.chat-nick {
  font-weight: 700;
  color: var(--text);
}
.chat-nick.is-owner::after {
  content: ' · 방장';
  font-weight: 500;
  color: var(--text-muted);
}
.chat-body {
  font-size: 0.95rem;
  word-break: break-word;
  line-height: 1.4;
}
.chat-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.chat-form .chat-input-wrap {
  flex: 1 1 12rem;
  min-width: 0;
}
.chat-form .chat-input-wrap input {
  width: 100%;
}
.chat-form .btn {
  flex: 0 0 auto;
}
.chat-form input:disabled,
.chat-form button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 720px) {
  .nav-tools { display: none; }
  .mobile-nav-toggle { display: inline-flex; }
  .nav.is-open .nav-tools {
    display: flex;
    flex-direction: column;
    position: absolute;
    right: 1rem;
    top: 4rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.5rem;
    box-shadow: var(--shadow);
  }
}
@media (min-width: 721px) {
  .mobile-nav-toggle { display: none; }
}

.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  min-height: 100vh;
}
.admin-nav {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1rem;
}
.admin-nav a {
  display: block;
  padding: 0.65rem 0.75rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 8px;
  min-height: var(--touch);
}
.admin-nav a:hover { background: var(--surface); }
.admin-main { padding: 1.25rem; }
@media (max-width: 800px) {
  .admin-layout { grid-template-columns: 1fr; }
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
table.data th, table.data td {
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0.4rem;
  text-align: left;
}

.roulette-canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  margin: 1rem auto;
  width: min(100%, 360px);
}
.roulette-pointer {
  position: absolute;
  top: 2px;
  left: 50%;
  z-index: 2;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 20px solid var(--accent);
  transform: translateX(-50%);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}
#rouletteCanvas {
  width: 100%;
  height: auto;
  border-radius: 50%;
  box-shadow: var(--shadow);
}
.roulette-winner {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  margin: 0.75rem 0 0;
}
.roulette-spinning {
  text-align: center;
  margin: 0.75rem 0 0;
}

.ladder-wrap {
  overflow-x: auto;
  margin: 0.5rem 0 1rem;
  padding-bottom: 0.35rem;
}
.ladder-svg {
  display: block;
  min-width: 100%;
  height: auto;
}
.ladder-mapping {
  margin: 0;
  padding-left: 1.25rem;
}

.bracket-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.bracket-pyramid {
  display: flex;
  align-items: stretch;
  gap: 1.25rem;
  overflow-x: auto;
  padding: 0.5rem 0 1rem;
  min-height: 22rem;
}
.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 11.5rem;
  flex: 0 0 auto;
}
.bracket-round-title {
  font-size: 1rem;
  text-align: center;
  margin-bottom: 0.75rem;
}
.bracket-round-body {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  flex: 1;
  gap: 1rem;
}
.bracket-match {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.45rem;
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}
.bracket-vs {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.15rem 0;
}
.bracket-note {
  margin: 0.25rem 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.bracket-slot {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: var(--touch);
  padding: 0.45rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-align: left;
}
.bracket-slot.is-empty {
  color: var(--text-muted);
  font-weight: 500;
}
.bracket-slot.is-pickable {
  cursor: pointer;
}
.bracket-slot.is-pickable:hover,
.bracket-slot.is-pickable:focus-visible {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 16%, var(--surface));
}
.bracket-slot.is-winner {
  background: color-mix(in srgb, var(--brand) 22%, var(--bg-elevated));
  border-color: var(--brand);
}
.bracket-slot:disabled {
  cursor: default;
}
.bracket-champion {
  margin: auto 0;
  padding: 1.25rem 1rem;
  text-align: center;
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-elevated));
  border: 1px solid var(--accent);
  animation: rise 0.45s ease both;
}
.bracket-champion-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.bracket-champion-name {
  margin: 0.35rem 0 0;
  font-size: 1.4rem;
  font-weight: 800;
}

.page-board {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
}
.board-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.board-hint {
  margin: 0.75rem 1.25rem 0;
}
.board-stage {
  padding: 1.25rem;
}
.page-board .bracket-slot,
.page-board .bracket-round-title,
.page-board .bracket-champion-name {
  font-size: 1.05rem;
}
.page-board .bracket-champion-name {
  font-size: 1.8rem;
}
