:root {
  --paper: #eef1f4;
  --surface: #fbfcfd;
  --surface-muted: #f5f7f9;
  --surface-strong: #e8edf1;
  --ink: #191c1f;
  --muted: #68717b;
  --faint: #8b949e;
  --line: #cfd6dc;
  --soft-line: #e2e7eb;
  --accent: #202326;
  --accent-hover: #0f1113;
  --red: #9f3434;
  --red-soft: #faeeee;
  --focus: rgba(32, 35, 38, 0.18);
  --shadow-panel: 0 14px 34px rgba(40, 48, 56, 0.07);
  --shadow-control: 0 1px 2px rgba(32, 35, 38, 0.06);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --radius-panel: 12px;
  --radius-control: 9px;
  --content-width: 1520px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Pretendard Variable", Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

#drawNumber:disabled {
  cursor: wait;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-header {
  position: sticky;
  top: 8px;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  width: min(var(--content-width), calc(100% - clamp(32px, 5vw, 72px)));
  min-height: 60px;
  margin: 8px auto 0;
  padding: 7px 9px 7px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: rgba(251, 252, 253, 0.96);
  box-shadow: 0 8px 24px rgba(40, 48, 56, 0.08);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand h1 {
  color: var(--ink);
  font-size: 23px;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
}

.tool-nav {
  display: flex;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 3px;
  border: 1px solid var(--soft-line);
  border-radius: 11px;
  background: var(--surface-muted);
}

.tool-tab,
.lang-button,
.segment,
.tool-mode,
.quick-times button {
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--muted);
}

.tool-tab {
  min-width: 0;
  min-height: 39px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #525b64;
  font-size: 16px;
  font-weight: 720;
  line-height: 1;
  white-space: nowrap;
}

.tool-tab.active {
  border-color: var(--soft-line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(32, 35, 38, 0.08);
}

.tab-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid currentColor;
  border-radius: 6px;
  color: inherit;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  opacity: 0.72;
}

.tool-tab.active .tab-icon {
  opacity: 1;
}

.language-switch {
  display: flex;
  padding: 3px;
  border: 1px solid var(--soft-line);
  border-radius: 11px;
  background: var(--surface-muted);
}

.lang-button {
  min-width: 69px;
  height: 36px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.lang-button.active {
  border-color: var(--soft-line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-control);
}

.app-main {
  width: min(var(--content-width), calc(100% - clamp(32px, 5vw, 72px)));
  margin: 0 auto;
  padding: 10px 0 18px;
}

.tool-view {
  display: none;
}

.tool-view.active {
  display: block;
}

.tool-grid {
  display: grid;
  gap: 10px;
  min-height: calc(100dvh - 96px);
}

.two-column,
.wide-result {
  grid-template-columns: minmax(272px, 314px) minmax(0, 1fr);
  align-items: stretch;
}

.panel,
.result-panel,
.timer-shell,
.board-toolbar,
.canvas-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
}

.panel,
.result-panel,
.timer-shell {
  position: relative;
  overflow: hidden;
}

.panel {
  min-height: calc(100dvh - 96px);
  padding: 24px 22px;
  background: var(--surface-muted);
}

.result-panel {
  container-type: inline-size;
  min-height: calc(100dvh - 96px);
  padding: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-panel);
}

.section-heading {
  margin-bottom: 24px;
}

.section-heading.centered {
  text-align: center;
}

.section-heading.compact {
  margin-bottom: 0;
}

.section-heading.compact h2 {
  font-size: 24px;
}

.section-heading.compact .eyebrow {
  margin-bottom: 4px;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  font-size: 31px;
  font-weight: 820;
  line-height: 1.15;
}

h3 {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
  color: #343a40;
  font-size: 14px;
  font-weight: 720;
}

input,
textarea {
  width: 100%;
  min-height: 45px;
  border: 1px solid #c7ced5;
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  box-shadow: inset 0 1px 1px rgba(32, 35, 38, 0.025);
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

input::placeholder,
textarea::placeholder {
  color: #8a939c;
  opacity: 1;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  background: #fcfdfe;
  box-shadow: 0 0 0 3px var(--focus);
}

textarea {
  resize: vertical;
  min-height: 180px;
  line-height: 1.5;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-bottom: 12px;
  font-weight: 650;
}

.check-line input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  box-shadow: none;
}

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

.number-actions .primary-button {
  width: 100%;
  min-height: 78px;
  font-size: 27px;
}

.reset-row {
  margin-top: 34px;
}

.reset-row .plain-button {
  width: 100%;
  min-height: 43px;
}

.centered-row {
  justify-content: center;
}

.primary-button,
.plain-button {
  min-height: 46px;
  border: 1px solid #aeb7bf;
  border-radius: var(--radius-control);
  padding: 0 17px;
  background: var(--surface);
  color: var(--ink);
  font-size: 17px;
  font-weight: 780;
  line-height: 1;
  white-space: nowrap;
  box-shadow: var(--shadow-control);
  transition: transform 140ms var(--ease-out), border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.primary-button {
  border-color: #9ba5ae;
  background: var(--surface-strong);
  box-shadow: 0 3px 10px rgba(40, 48, 56, 0.09), inset 0 1px 0 rgba(251, 252, 253, 0.8);
}

.primary-button:active,
.plain-button:active,
.tool-tab:active,
.lang-button:active,
.tool-mode:active,
.quick-times button:active {
  transform: scale(0.97);
}

.danger {
  border-color: #d8a7a7;
  background: var(--red-soft);
  color: var(--red);
}

.hint {
  min-height: 19px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 520;
  line-height: 1.5;
}

.number-stage {
  display: grid;
  grid-template-rows: minmax(360px, 1fr) auto;
  gap: 0;
  align-items: stretch;
}

.number-result {
  display: grid;
  place-items: center;
  min-height: 430px;
  border-bottom: 1px solid var(--soft-line);
  color: var(--accent);
  font-size: clamp(96px, 20cqi, 230px);
  font-weight: 850;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  transition: transform 140ms var(--ease-out), opacity 140ms ease;
}

.number-result.spinning {
  opacity: 0.52;
  transform: scale(0.985);
}

.history-block {
  min-height: 105px;
  padding-top: 17px;
}

.history-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 34px;
}

.chip-list:empty::before {
  content: attr(data-empty-label);
  color: var(--faint);
  font-size: 13px;
  line-height: 32px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface-muted);
  color: #343a40;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.board-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--soft-line);
}

.subtle {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 9px;
  width: 100%;
  min-height: 430px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: #424950;
  font-size: 17px;
  font-weight: 760;
}

.empty-state span:last-child {
  max-width: 34ch;
  font-size: 14px;
  line-height: 1.5;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  color: var(--ink);
  font-size: 23px;
}

.seat-layout {
  display: grid;
  gap: 16px;
  overflow: hidden;
  padding-bottom: 8px;
}

.classroom-front {
  border-radius: 8px;
  background: var(--accent);
  color: var(--surface);
  padding: 11px 12px;
  text-align: center;
  font-size: 14px;
  font-weight: 820;
  letter-spacing: 0;
}

.seat-sections-wrap {
  display: grid;
  gap: clamp(6px, 1vw, 14px);
  align-items: start;
  width: 100%;
}

.seat-section {
  min-width: 0;
}

.section-label,
.group-title {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.seat {
  min-height: clamp(36px, 5.7vh, 54px);
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: clamp(4px, 0.8vh, 8px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 23px;
  font-weight: 820;
  line-height: 1;
  overflow-wrap: anywhere;
  user-select: none;
  transition: transform 140ms var(--ease-out), border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease, opacity 140ms ease;
}

.seat:last-child {
  margin-bottom: 0;
}

.seat.empty {
  background: var(--surface-muted);
  color: var(--faint);
  font-size: 13px;
  font-weight: 650;
}

.seat:not(.empty) {
  cursor: grab;
}

.seat.dragging {
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(40, 48, 56, 0.16);
  cursor: grabbing;
  opacity: 0.65;
  transform: scale(0.98);
}

.seat.drag-over {
  border-color: var(--accent);
  background: var(--surface-strong);
  box-shadow: inset 0 0 0 2px rgba(32, 35, 38, 0.16);
  transform: translateY(-1px);
}

.seat.selected {
  border-color: var(--accent);
  background: var(--surface-strong);
  box-shadow: inset 0 0 0 2px rgba(32, 35, 38, 0.16);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 4px 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  overflow: hidden;
}

.segment {
  min-height: 42px;
  border-radius: 0;
  font-weight: 760;
}

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

.segment.active {
  background: var(--accent);
  color: var(--surface);
}

.group-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.group-card {
  border-top: 2px solid var(--accent);
  border-radius: 0 0 var(--radius-control) var(--radius-control);
  background: var(--surface-muted);
  padding: 16px;
}

.group-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
  gap: 7px;
}

.group-member {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--soft-line);
  border-radius: 7px;
  background: var(--surface);
  padding: 6px;
  font-size: 16px;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.timer-shell {
  container-type: inline-size;
  width: 100%;
  min-height: calc(100dvh - 96px);
  margin: 0 auto;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 40px;
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.timer-shell.done {
  border-color: #c78080;
  box-shadow: 0 0 0 4px rgba(159, 52, 52, 0.1), var(--shadow-panel);
}

.timer-display {
  margin: 14px 0 30px;
  color: var(--ink);
  font-size: clamp(88px, 21cqi, 220px);
  font-weight: 820;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

.quick-times {
  display: grid;
  grid-template-columns: repeat(4, minmax(74px, 1fr));
  gap: 7px;
  width: min(520px, 100%);
  margin-bottom: 20px;
  padding: 4px;
  border: 1px solid var(--soft-line);
  border-radius: 11px;
  background: var(--surface-muted);
}

.quick-times button {
  min-height: 44px;
  font-weight: 760;
  transition: transform 140ms var(--ease-out), border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.quick-times button.active {
  border-color: var(--soft-line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-control);
}

.timer-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: min(340px, 100%);
}

.board-view.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  height: calc(100dvh - 96px);
  min-height: 560px;
}

.board-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: var(--surface);
  padding: 13px 15px;
  box-shadow: var(--shadow-control);
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  justify-content: flex-end;
}

.tool-mode {
  min-height: 42px;
  min-width: 72px;
  padding: 0 13px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 760;
  transition: transform 140ms var(--ease-out), border-color 150ms ease, background-color 150ms ease;
}

.tool-mode.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

.size-control {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
}

.size-control input {
  width: 120px;
  min-height: 42px;
  padding: 0;
  accent-color: var(--accent);
  box-shadow: none;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
}

#whiteboard {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: var(--surface);
}

#eraserPreview {
  position: absolute;
  z-index: 2;
  display: none;
  border: 1px solid rgba(32, 35, 38, 0.7);
  border-radius: 999px;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

#eraserPreview.visible {
  display: block;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .tool-tab:hover,
  .lang-button:hover {
    color: var(--ink);
    background: rgba(251, 252, 253, 0.72);
  }

  .primary-button:hover {
    border-color: #7f8992;
    background: #e1e7ec;
    box-shadow: 0 5px 14px rgba(40, 48, 56, 0.12), inset 0 1px 0 rgba(251, 252, 253, 0.85);
    transform: translateY(-1px);
  }

  .plain-button:hover,
  .quick-times button:hover,
  .tool-mode:hover,
  .segment:hover {
    border-color: #9fa9b2;
    background: var(--surface-strong);
  }

  .danger:hover {
    border-color: #c78080;
    background: #f7e4e4;
  }

  .seat:not(.empty):hover {
    border-color: #9fa9b2;
    background: var(--surface-muted);
    transform: translateY(-1px);
  }
}

@media (max-width: 1120px) {
  .app-header {
    grid-template-columns: 1fr auto;
    gap: 7px 12px;
    padding: 9px 10px 9px 16px;
  }

  .brand,
  .language-switch {
    grid-row: 1;
  }

  .language-switch {
    grid-column: 2;
  }

  .tool-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .tool-nav::-webkit-scrollbar {
    display: none;
  }

  .tool-tab {
    flex: 1 0 auto;
  }

  .two-column,
  .wide-result {
    grid-template-columns: minmax(260px, 292px) minmax(0, 1fr);
  }
}

@media (max-width: 840px) {
  .app-header,
  .app-main {
    width: calc(100% - 24px);
  }

  .two-column,
  .wide-result {
    grid-template-columns: 1fr;
  }

  .tool-grid,
  .panel,
  .result-panel,
  .timer-shell {
    min-height: auto;
  }

  .result-panel {
    min-height: 520px;
  }

  .board-view.active {
    height: auto;
  }

  .canvas-wrap {
    height: 68dvh;
    min-height: 440px;
  }
}

@media (max-width: 640px) {
  .app-header {
    top: 6px;
    width: calc(100% - 16px);
    margin-top: 6px;
    padding: 8px;
  }

  .brand h1 {
    padding-left: 3px;
    font-size: 20px;
  }

  .lang-button {
    min-width: 58px;
    height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }

  .tool-tab {
    min-height: 42px;
    padding: 0 10px;
    font-size: 15px;
  }

  .app-main {
    width: calc(100% - 16px);
    padding-top: 8px;
  }

  .panel,
  .result-panel,
  .timer-shell {
    padding: 19px 16px;
  }

  h2 {
    font-size: 28px;
  }

  .section-heading {
    margin-bottom: 20px;
  }

  .number-result {
    min-height: 330px;
    font-size: clamp(82px, 28cqi, 150px);
  }

  .number-actions .primary-button {
    min-height: 68px;
    font-size: 24px;
  }

  .empty-state {
    min-height: 330px;
  }

  .quick-times {
    grid-template-columns: 1fr 1fr;
  }

  .timer-display {
    font-size: clamp(72px, 28cqi, 128px);
  }

  .board-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-controls {
    justify-content: flex-start;
  }

  .size-control {
    width: 100%;
  }

  .size-control input {
    flex: 1;
  }
}

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

@media (prefers-reduced-transparency: reduce) {
  .app-header {
    background: var(--surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
