:root {
  color-scheme: light;
  --ink: #111;
  --muted: #747474;
  --line: #181818;
  --paper: #fbfbfa;
  --cell: #f2f2f2;
  --shade: #e5e5e5;
  --dark: #4b4b4b;
  --accent: #b91c1c;
  --accent-dark: #8f1717;
  --focus: #2563eb;
  font-family: Inter, "Noto Sans KR", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #ece9e2;
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(14px, 3vw, 30px);
  border-bottom: 2px solid var(--line);
  background: rgba(251, 251, 250, 0.96);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.05;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  transform: rotate(-6deg);
  box-shadow: 3px 3px 0 var(--ink);
}

.top-actions,
.game-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(14px, 3vw, 28px);
}

.notice {
  min-height: 0;
}

.notice:not(:empty) {
  margin-bottom: 12px;
  border: 2px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.setup-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 28px;
  align-items: start;
}

.setup-copy {
  padding-top: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 58px);
  line-height: 1.02;
  letter-spacing: 0;
}

.setup-copy p:last-child,
.muted {
  color: var(--muted);
}

.setup-copy p:last-child {
  max-width: 620px;
  font-size: 18px;
  line-height: 1.65;
}

.setup-form,
.join-panel,
.dice-calculator,
.player-picker,
.history-list article,
.summary-strip {
  border: 2px solid var(--line);
  background: var(--paper);
}

.setup-form {
  padding: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: #262626;
  font-size: 14px;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

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

.setup-form label + label {
  margin-top: 14px;
}

.primary-button,
.tool-button,
.icon-button,
.tab,
.score-fill-button {
  min-height: 40px;
  border: 2px solid var(--line);
  border-radius: 0;
  font-weight: 900;
}

.primary-button {
  background: var(--ink);
  color: #fff;
  padding: 8px 14px;
}

.primary-button:hover {
  background: #2b2b2b;
}

.tool-button,
.tab,
.score-fill-button {
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
}

.tool-button:hover,
.tab:hover,
.score-fill-button:hover {
  background: var(--shade);
}

.full {
  width: 100%;
  margin-top: 16px;
}

.game-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.game-head h1 {
  font-size: clamp(28px, 4vw, 44px);
}

.join-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 12px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 2px solid var(--line);
  margin-bottom: 12px;
}

.tab {
  border: 0;
  border-right: 2px solid var(--line);
  background: #fff;
}

.tab:last-child {
  border-right: 0;
}

.tab.active {
  background: var(--ink);
  color: #fff;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.summary-item {
  min-height: 78px;
  padding: 10px;
  border-right: 1px solid var(--line);
}

.summary-item:last-child {
  border-right: 0;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-item strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(22px, 5vw, 34px);
}

.player-picker {
  display: grid;
  gap: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.dice-calculator {
  padding: 12px;
  margin-bottom: 12px;
}

.dice-calculator-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.dice-calculator strong {
  font-size: 16px;
}

.dice-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(44px, 1fr));
  gap: 8px;
}

.die-select {
  min-height: 48px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
}

.score-list {
  display: grid;
  gap: 8px;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 88px 84px;
  gap: 8px;
  align-items: center;
  border: 2px solid var(--line);
  background: var(--paper);
  padding: 8px;
}

.score-row.done {
  background: #ececec;
}

.score-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 900;
}

.score-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.dice-mini {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  line-height: 1;
}

.score-row input {
  min-height: 42px;
  text-align: right;
  font-size: 18px;
  font-weight: 900;
}

.score-fill-button {
  padding: 6px;
  white-space: nowrap;
}

.scorecard-wrap {
  overflow-x: auto;
  border: 2px solid var(--line);
  background: #fff;
}

.scorecard {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  table-layout: fixed;
}

.scorecard th,
.scorecard td {
  height: 50px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: right;
  font-weight: 800;
}

.scorecard thead th {
  height: 58px;
  border-bottom: 3px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 18px;
}

.scorecard .category-cell {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 210px;
  background: #fff;
  text-align: left;
}

.scorecard tbody tr:nth-child(odd) td:not(.category-cell),
.scorecard thead th:nth-child(odd):not(.category-cell) {
  background: var(--cell);
}

.scorecard .bonus-row .category-cell,
.scorecard .total-row .category-cell {
  background: var(--dark);
  color: #fff;
}

.scorecard .bonus-row td:not(.category-cell) {
  background: #b8b8b8;
  color: #fff;
  font-size: 22px;
}

.scorecard .total-row td {
  height: 64px;
  font-size: 24px;
  border-top: 3px solid var(--line);
}

.scorecard .separator-row td {
  height: 10px;
  padding: 0;
  border-left: 0;
  border-right: 0;
  background: #fff;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-list article {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
}

.history-list h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.history-list p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.modal {
  width: min(360px, calc(100vw - 28px));
  border: 3px solid var(--line);
  padding: 14px;
  background: var(--paper);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.modal img {
  width: 100%;
  border: 2px solid var(--line);
  background: #fff;
}

.modal input {
  margin-top: 10px;
  font-size: 12px;
}

@media (max-width: 780px) {
  .setup-view,
  .join-panel,
  .game-head,
  .history-list article {
    grid-template-columns: 1fr;
  }

  .setup-copy {
    padding-top: 0;
  }

  .topbar {
    align-items: start;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: end;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-item:nth-child(2) {
    border-right: 0;
  }

  .summary-item:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .score-row {
    grid-template-columns: minmax(0, 1fr) 78px;
  }

  .score-fill-button {
    grid-column: 1 / -1;
  }

  .brand strong {
    font-size: 17px;
  }
}

@media (max-width: 480px) {
  main {
    padding: 12px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .tool-button,
  .primary-button {
    padding-inline: 10px;
  }

  .dice-row {
    grid-template-columns: repeat(5, minmax(38px, 1fr));
  }

  .die-select {
    padding-inline: 4px;
  }
}
