:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --line: #d9d9d4;
  --text: #1b1b19;
  --muted: #6b6b64;
  --accent: #1f6f4a;
  --accent-text: #ffffff;
  --ok: #1f6f4a;
  --warn: #8a5a00;
  --bad: #a02020;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --panel: #1f1f1e;
    --line: #35352f;
    --text: #eceae4;
    --muted: #a3a199;
    --accent: #3f9e6c;
    --accent-text: #10231a;
    --ok: #6fbf8f;
    --warn: #d8a24a;
    --bad: #e07070;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 2;
  flex-wrap: wrap;
}

.brand {
  font-weight: 600;
  letter-spacing: 0;
}

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tabs button {
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
}

.tabs button[aria-selected="true"] {
  background: var(--bg);
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
}

main {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 1100px;
}

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

/* .page 의 display:flex 가 hidden 속성의 기본 display:none 을 덮어쓴다.
   이 규칙이 없으면 화면 4개가 한꺼번에 렌더된다. */
.page[hidden] {
  display: none;
}

.band {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px;
}

.band.grow {
  min-height: 160px;
}

.band.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}

h2 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0;
}

.sep {
  width: 1px;
  align-self: stretch;
  background: var(--line);
}

label {
  color: var(--muted);
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  min-width: 0;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.segmented button {
  border: none;
  border-radius: 0;
  background: var(--panel);
  color: var(--muted);
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button.on {
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}

.grid {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.grid th,
.grid td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.grid th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.grid .num,
.grid td.num {
  text-align: right;
}

.grid td.actions,
.grid th.actions {
  text-align: right;
  white-space: nowrap;
}

.name {
  font-weight: 600;
}

.hanja-slot {
  display: inline-block;
  margin-right: 8px;
}

.tag {
  display: inline-block;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  padding: 0 5px;
  font-size: 12px;
}

.tag.ok {
  color: var(--ok);
}

.tag.warn {
  color: var(--warn);
}

.tag.bad {
  color: var(--bad);
}

.meta {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 13px;
}

.error {
  color: var(--bad);
  margin: 8px 0 0;
  min-height: 1.5em;
}

.result {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result .headline {
  font-size: 18px;
  font-weight: 600;
}

.vote-on {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

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

@media (max-width: 640px) {
  /* 좁은 화면에서는 '표' 열(누가 어떤 표를 했는지)을 접는다. 점수와 투표 버튼은 남긴다. */
  #candidate-table th:nth-child(5),
  #candidate-table td:nth-child(5) {
    display: none;
  }
}

.legal {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}

.legal a {
  color: var(--muted);
  font-size: 13px;
}
