:root {
  --bg: #FFF9EC;
  --fg: #252A30;
  --accent: #BE3E26;
  --surface: #FFFFFF;
  --border: #DCCFB9;
  --radius: 14px;
  --muted: #6C665C;
  --result-bg: #FFF0CF;
  --focus: #215DA8;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
}

.app-shell {
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.site-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.site-nav {
  display: flex;
  gap: 0.5rem;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.4rem 1rem;
  border-radius: calc(var(--radius) - 4px);
  color: var(--fg);
  text-decoration: none;
  font-weight: 500;
  border: 1px solid transparent;
}

.nav-link:hover {
  background: var(--surface);
  border-color: var(--border);
}

.nav-link.router-link-active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 1.1rem;
  font: inherit;
  font-weight: 600;
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  border: 2px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-outline {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline:hover:not(:disabled) {
  background: #fff8f5;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--fg);
}

.btn-block {
  width: 100%;
}

.btn-small {
  min-height: 44px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
}

.btn-small:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* Game page */
.game-page {
  overflow-x: hidden;
}

.game-intro {
  margin-bottom: 1.25rem;
}

.intro-heading {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 4vw, 1.875rem);
  font-weight: 700;
  line-height: 1.25;
}

.intro-text {
  margin: 0;
  color: var(--muted);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.input-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.section-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.section-desc {
  margin: 0 0 0.85rem;
  font-size: 0.9375rem;
  color: var(--muted);
}

.textarea-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.field-label textarea {
  width: 100%;
  min-height: 8rem;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}

.field-label textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.field-label textarea:disabled {
  opacity: 0.65;
}

.status-block .count-display {
  margin: 0 0 0.35rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.ready-hint {
  margin: 0;
  color: var(--accent);
  font-weight: 500;
}

.msg {
  margin: 0.65rem 0 0;
  font-size: 0.9375rem;
}

.msg-error {
  color: var(--accent);
  font-weight: 600;
}

.msg-loading {
  color: var(--muted);
}

.msg-status {
  color: var(--fg);
}

.msg-muted {
  color: var(--muted);
}

.ladder-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ladder-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.25rem;
  min-height: 200px;
}

.ladder-placeholder {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.ladder-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
}

.toolbar-note {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}

.ladder-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  padding-bottom: 0.5rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.ladder-board {
  padding: 0.75rem 0.5rem 1rem;
}

.ladder-names,
.ladder-outcomes {
  display: flex;
  flex-wrap: nowrap;
}

.name-col,
.outcome-col {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0 4px;
  text-align: center;
}

.name-col.is-active .name-text {
  color: var(--accent);
  font-weight: 700;
}

.name-text,
.outcome-text {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  font-weight: 600;
}

.outcome-col .outcome-text {
  padding: 0.35rem 0.25rem;
  border-radius: 8px;
  background: #e8e4dc;
  color: var(--muted);
  min-height: 2rem;
  line-height: 1.3;
}

.outcome-col.is-visible .outcome-text {
  background: var(--result-bg);
  color: var(--fg);
  white-space: normal;
  word-break: break-word;
  overflow: visible;
}

.ladder-svg {
  display: block;
  margin: 0 auto;
}

.line-vertical,
.line-horizontal {
  stroke: #1a1a1a;
  stroke-width: 2;
  stroke-linecap: round;
}

.line-path {
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0;
  transition: opacity 0.08s linear;
}

.line-path.visible {
  opacity: 1;
}

.path-end {
  fill: var(--accent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.path-highlight .path-end {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .line-path {
    transition: none;
  }
}

.results-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.results-empty,
.results-list--empty {
  margin: 0;
  color: var(--muted);
  list-style: none;
  padding: 0;
}

.results-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.result-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.result-item.is-highlighted {
  border-color: var(--accent);
  background: var(--result-bg);
}

.result-participant {
  font-weight: 700;
  word-break: break-word;
}

.result-outcome {
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

.result-arrow {
  color: var(--muted);
  flex-shrink: 0;
}

/* Guide */
.guide-page {
  max-width: 720px;
}

.guide-page h1 {
  margin: 0 0 1rem;
  font-size: clamp(1.5rem, 4vw, 1.875rem);
}

.guide-content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.guide-section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.guide-section p,
.guide-section ul {
  margin: 0;
  color: var(--fg);
}

.guide-section ul {
  padding-left: 1.25rem;
}

.guide-section li + li {
  margin-top: 0.35rem;
}

.guide-step {
  margin: 0 0 0.35rem;
}

.guide-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 700;
}

.guide-cta {
  margin-top: 1rem;
  text-decoration: none;
}

/* Responsive */
@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 359px) {
  .textarea-row {
    grid-template-columns: 1fr;
  }
}
