:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #f0f3f6;
  --text: #171a1f;
  --muted: #66717f;
  --line: #d9dee6;
  --danger: #c93a3a;
  --danger-soft: #fff0f0;
  --primary: #175edc;
  --primary-dark: #0f48ab;
  --shadow: 0 16px 36px rgba(27, 36, 52, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Pretendard",
    "Segoe UI",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  letter-spacing: 0;
}

body.is-paused .app-shell {
  filter: grayscale(1);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 16px 20px;
  background: #101722;
  color: #ffffff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: #798595;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #92a2b8;
}

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

h1 {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 21px;
  line-height: 1.25;
}

h3 {
  font-size: 17px;
  line-height: 1.3;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.status-badge,
.small-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #e8edf4;
  color: #2f3a47;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.topbar .status-badge {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.topbar .status-badge.is-live {
  background: rgba(32, 155, 98, 0.22);
  color: #c9f8df;
}

.topbar .status-badge.is-offline {
  background: rgba(201, 58, 58, 0.22);
  color: #ffd2d2;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(390px, 0.95fr);
  gap: 18px;
  margin-top: 18px;
}

.scoreboard-mode .layout {
  grid-template-columns: 1fr;
}

.scoreboard-mode .app-shell {
  width: min(1680px, 100%);
}

.board-section,
.control-section,
.tool-panel,
.empty-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 26px rgba(30, 42, 58, 0.06);
}

.board-section,
.control-section {
  padding: 18px;
}

.section-head,
.panel-title-row,
.active-team-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.round-meter {
  display: grid;
  grid-template-columns: repeat(8, 26px);
  gap: 5px;
  align-items: center;
}

.round-meter span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #edf1f6;
  color: #394555;
  font-size: 12px;
  font-weight: 900;
}

.teams-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.team-card {
  min-height: 148px;
  padding: 14px;
  border: 1px solid var(--line);
  border-top: 5px solid var(--team-color);
  border-radius: var(--radius);
  background: #ffffff;
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.team-card:hover,
.team-card:focus-visible {
  border-color: var(--team-color);
  box-shadow: 0 12px 24px rgba(26, 36, 52, 0.12);
  transform: translateY(-1px);
  outline: none;
}

.team-card.is-active {
  border-color: var(--team-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--team-color) 20%, transparent);
}

.team-card.is-out {
  background: #f4f4f4;
  color: #6c727a;
}

.team-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.team-number {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--team-color);
  color: #ffffff;
  font-weight: 900;
}

.team-name {
  font-size: 18px;
  font-weight: 900;
}

.team-hp {
  margin-top: 14px;
}

.hp-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.hp-value {
  color: var(--text);
  font-size: 22px;
  font-weight: 950;
}

.hp-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e9ee;
}

.hp-fill {
  height: 100%;
  width: var(--hp-width);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--hp-color), color-mix(in srgb, var(--hp-color) 72%, #ffffff));
  transition: width 220ms ease;
}

.team-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
}

.segmented button {
  min-width: 54px;
  min-height: 32px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #455061;
  font-weight: 900;
}

.segmented button.is-selected {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 4px 12px rgba(28, 42, 61, 0.12);
}

.empty-panel {
  display: grid;
  gap: 7px;
  margin-top: 16px;
  padding: 30px;
  min-height: 180px;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-panel strong {
  color: var(--text);
  font-size: 18px;
}

#captainPanel {
  margin-top: 16px;
}

#adminPanel {
  margin-top: 16px;
}

.active-team-row {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fafc;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.tool-panel {
  padding: 14px;
}

.history-panel {
  margin-top: 12px;
}

.admin-panel-grid {
  align-items: start;
}

.admin-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.scoreboard-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(360px, 0.65fr);
  gap: 14px;
  margin-top: 16px;
}

.scoreboard-panel[hidden] {
  display: none;
}

.inventory-list,
.target-list,
.history-list,
.ticket-list,
.mini-history-list,
.ranking-list,
.admin-inventory-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.inventory-list {
  min-height: 236px;
}

.target-list {
  max-height: 330px;
  overflow: auto;
  padding-right: 3px;
}

.weapon-card,
.target-card,
.history-item,
.draw-option,
.discard-option,
.ticket-option,
.ticket-team-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.weapon-card,
.draw-option,
.discard-option {
  padding: 12px;
  border-left: 5px solid var(--grade-color);
}

.weapon-card {
  text-align: left;
}

.weapon-card.is-selected {
  border-color: var(--grade-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--grade-color) 18%, transparent);
}

.weapon-main,
.target-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.weapon-name,
.target-name {
  font-weight: 950;
}

.grade-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--grade-color);
  color: var(--grade-text, #ffffff);
  font-weight: 950;
}

.weapon-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.stat {
  padding: 7px 8px;
  border-radius: 6px;
  background: #f0f3f6;
  color: #3f4a58;
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.weapon-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.empty-slot,
.empty-list {
  display: grid;
  min-height: 92px;
  place-items: center;
  border: 1px dashed #c6ced8;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.target-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  text-align: left;
  border-left: 5px solid var(--team-color);
}

.target-card.is-selected {
  border-color: var(--team-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--team-color) 18%, transparent);
}

.target-card.is-disabled {
  opacity: 0.45;
}

.target-card .hp-bar {
  height: 9px;
}

.ticket-option,
.ticket-team-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  text-align: left;
}

.ticket-option {
  border-left: 5px solid var(--primary);
}

.ticket-option.is-special {
  border-left-color: #f2b705;
  background: #fffaf0;
}

.ticket-option:hover,
.ticket-option:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 94, 220, 0.14);
  outline: none;
}

.ticket-option strong,
.ticket-team-row strong {
  display: block;
  margin-bottom: 3px;
  font-size: 14px;
}

.ticket-option span,
.ticket-team-row span:not(.small-badge) {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ticket-team-row {
  border-left: 5px solid var(--team-color);
}

.ticket-detail-list {
  display: grid;
  gap: 6px;
  margin: -2px 0 8px 14px;
  padding-left: 12px;
  border-left: 2px solid var(--line);
}

.ticket-detail-row,
.admin-item-row,
.mini-history-item,
.ranking-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.ranking-row {
  border-left: 5px solid var(--team-color);
}

.rank-number {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--team-color);
  color: #ffffff;
  font-weight: 950;
}

.ranking-row div {
  min-width: 0;
  flex: 1;
}

.ranking-row strong,
.mini-history-item strong {
  display: block;
  margin-bottom: 2px;
}

.ranking-row span:not(.small-badge):not(.rank-number),
.mini-history-item span,
.ticket-detail-row span,
.admin-item-row span,
.empty-mini {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.empty-mini {
  padding: 8px 10px;
  border: 1px dashed #c6ced8;
  border-radius: 7px;
  text-align: center;
}

.admin-adjust-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.admin-team-detail {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--team-color);
  border-radius: var(--radius);
  background: #ffffff;
}

.weapon-book {
  display: grid;
  gap: 16px;
}

.weapon-grade-section {
  display: grid;
  gap: 10px;
}

.weapon-book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.weapon-book-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--grade-color);
  border-radius: var(--radius);
  background: #ffffff;
}

.compact-button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.target-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.history-list {
  max-height: 210px;
  overflow: auto;
}

.history-item {
  padding: 10px 12px;
}

.history-item strong {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
}

.history-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.primary-button,
.ghost-button,
.danger-button,
.plain-button {
  min-height: 38px;
  padding: 9px 14px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-weight: 900;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover:not(:disabled),
.primary-button:focus-visible {
  background: var(--primary-dark);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f1b7b7;
}

.plain-button {
  background: #ffffff;
  color: #2e3744;
  border-color: var(--line);
}

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

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(13, 19, 30, 0.52);
}

.modal-root[hidden] {
  display: none;
}

.modal {
  width: min(560px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.modal-header,
.modal-body,
.modal-footer {
  padding: 16px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: #303948;
  font-size: 20px;
  line-height: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--line);
}

.modal-footer:empty {
  display: none;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: #35404e;
  font-size: 13px;
  font-weight: 900;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #bbc5d2;
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(23, 94, 220, 0.14);
}

.range-preview {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
}

.range-chip {
  min-height: 58px;
  padding: 8px;
  border-radius: 7px;
  background: #f0f3f6;
  color: #505b6b;
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.range-chip.is-active {
  background: #e5efff;
  color: var(--primary);
  box-shadow: inset 0 0 0 2px rgba(23, 94, 220, 0.28);
}

.draw-grid,
.discard-grid {
  display: grid;
  gap: 10px;
}

.draw-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.discard-grid {
  grid-template-columns: 1fr;
}

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

.damage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
  font-weight: 850;
}

.damage-row span:last-child {
  color: var(--danger);
}

.damage-row.heal-row span:last-child {
  color: #209b62;
}

.damage-row.reduction-row span:last-child {
  color: #df8a20;
}

.hit-flash {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  background: rgba(201, 58, 58, 0.42);
  animation: hit-flash 900ms ease-out forwards;
}

.hit-notice {
  position: fixed;
  top: 92px;
  left: 50%;
  z-index: 81;
  display: grid;
  gap: 5px;
  width: min(520px, calc(100vw - 32px));
  padding: 16px 18px;
  border: 1px solid rgba(201, 58, 58, 0.55);
  border-left: 6px solid var(--danger);
  border-radius: var(--radius);
  background: #fff7f7;
  color: #341818;
  box-shadow: 0 18px 46px rgba(30, 20, 20, 0.24);
  transform: translateX(-50%);
  animation: hit-notice 5200ms ease forwards;
}

.hit-notice strong {
  color: var(--danger);
  font-size: 16px;
  font-weight: 950;
}

.hit-notice span {
  font-size: 14px;
  font-weight: 850;
}

@keyframes hit-flash {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes hit-notice {
  0% {
    opacity: 0;
    transform: translate(-50%, -12px);
  }

  8%,
  86% {
    opacity: 1;
    transform: translate(-50%, 0);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  width: min(420px, calc(100vw - 36px));
  padding: 13px 14px;
  border-radius: var(--radius);
  background: #101722;
  color: #ffffff;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 850;
}

.pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
  background: rgba(116, 123, 132, 0.58);
}

.pause-overlay[hidden] {
  display: none;
}

.pause-overlay strong {
  padding: 18px 24px;
  border: 3px solid #c93a3a;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: #c93a3a;
  box-shadow: 0 20px 60px rgba(30, 36, 44, 0.24);
  font-size: clamp(28px, 5vw, 64px);
  font-weight: 950;
  text-align: center;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .section-head,
  .active-team-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .section-head {
    width: 100%;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .teams-grid,
  .panel-grid,
  .scoreboard-panel,
  .admin-adjust-grid,
  .draw-grid,
  .range-preview {
    grid-template-columns: 1fr;
  }

  .round-meter {
    grid-template-columns: repeat(8, minmax(22px, 1fr));
    width: 100%;
  }

  .round-meter span {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .modal-footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .modal-footer button {
    width: 100%;
  }
}
