:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #637181;
  --paper: #ffffff;
  --line: #d9e0e7;
  --canvas: #f4f7f8;
  --green: #087f5b;
  --green-dark: #065f46;
  --green-soft: #e5f4ed;
  --yellow: #f2c94c;
  --red: #c2413d;
  --blue: #2563a8;
  --shadow: 0 14px 36px rgba(23, 33, 43, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic", "Hiragino Sans", Meiryo, sans-serif;
  line-height: 1.6;
}

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

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  min-height: 132px;
  padding: 22px clamp(16px, 4vw, 48px);
  background: #0d322c;
  color: #ffffff;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: clamp(24px, 5vw, 38px);
  line-height: 1.15;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #b7d9ce;
}

.source-pill {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  color: #e8fff6;
  font-size: 13px;
  font-weight: 700;
}

.topbar-media {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.trophy-board {
  width: clamp(138px, 24vw, 260px);
  height: auto;
  max-height: 150px;
  object-fit: contain;
  object-position: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #050505;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22);
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 28px) 32px;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-height: 82px;
  padding: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(18px, 3vw, 26px);
  line-height: 1.2;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 0 12px;
  background: var(--canvas);
}

.tab-button {
  background: #ffffff;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 800;
}

.tab-button.active {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
  box-shadow: 0 8px 20px rgba(8, 127, 91, 0.18);
}

.tab-panel {
  display: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(14px, 3vw, 24px);
  box-shadow: var(--shadow);
}

.tab-panel.active {
  display: block;
}

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

.section-head h2 {
  margin: 2px 0 0;
  font-size: clamp(21px, 3vw, 30px);
  line-height: 1.2;
}

.control-row,
.action-row,
.admin-grid {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
  flex: 1 1 210px;
}

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

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

.field textarea {
  resize: vertical;
}

.small-field,
.compact-field {
  flex: 0 1 150px;
}

.search-field {
  flex: 2 1 280px;
}

.primary-button {
  background: var(--green);
  color: #ffffff;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--green-dark);
}

.secondary-button {
  background: #e8eef3;
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
}

.ghost-button {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--line);
  padding: 0 14px;
  font-weight: 800;
}

.danger-button {
  background: #fee2e2;
  color: #991b1b;
  padding: 0 14px;
  font-weight: 800;
}

.selected-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 16px 0;
  padding: 14px;
  background: var(--green-soft);
  border: 1px solid #b6decf;
  border-radius: 8px;
}

.selected-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

#selectedTeamName {
  display: block;
  min-width: 180px;
  margin-top: 2px;
  font-size: 20px;
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(152px, 1fr));
  gap: 10px;
}

.team-card {
  min-height: 154px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
}

.team-card.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.15);
}

.team-card.eliminated {
  opacity: 0.72;
  background: #f8fafc;
}

.flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 28px;
  font-size: 24px;
  line-height: 1;
}

.flag-img {
  display: inline-block;
  flex: 0 0 auto;
  width: 56px;
  height: 36px;
  object-fit: contain;
  vertical-align: middle;
}

.flag-img.large {
  width: 64px;
  height: 42px;
}

.flag-img.small {
  width: 42px;
  height: 27px;
}

.flag-img.tiny {
  width: 30px;
  height: 20px;
}

.team-card-flag {
  display: block;
  min-height: 38px;
}

.team-code {
  display: block;
  margin-top: 8px;
  color: #0f172a;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0;
}

.team-name {
  display: block;
  margin-top: 2px;
  font-weight: 900;
}

.team-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  vertical-align: middle;
}

.team-inline.empty {
  color: var(--muted);
}

.team-inline strong {
  font-weight: 900;
}

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

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-chip.alive {
  background: #dcfce7;
  color: #166534;
}

.status-chip.winner {
  background: #fef3c7;
  color: #92400e;
}

.ranking-list,
.prize-board,
.pick-list,
.schedule-list,
.phase-list,
.group-board,
.guide-grid,
.name-editor {
  display: grid;
  gap: 10px;
}

.ranking-card,
.prize-card,
.pick-row,
.match-row,
.phase-row,
.group-card,
.guide-card,
.name-row {
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.ranking-card {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.rank-number {
  display: grid;
  place-items: center;
  min-width: 58px;
  min-height: 40px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
}

.ranking-empty {
  padding: 16px;
  border: 1px dashed #b8c5d2;
  border-radius: 8px;
  background: #f8fafc;
}

.match-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 900;
}

.versus {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.ranking-card:first-child .rank-number {
  background: var(--yellow);
  color: #472f00;
}

.score {
  color: var(--green-dark);
  font-size: 22px;
  font-weight: 900;
}

.award-line {
  margin-top: 4px;
  color: #8a5a00;
  font-size: 13px;
  font-weight: 900;
}

.prize-board {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 14px;
}

.prize-card {
  min-height: 76px;
  align-content: center;
  background: #fff9e8;
  border-color: #f0d27a;
}

.prize-card strong {
  color: #8a5a00;
  font-size: 18px;
}

.prize-card span {
  font-weight: 900;
}

.subhead {
  margin: 24px 0 10px;
  font-size: 18px;
}

.pick-row,
.match-row,
.phase-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.match-row.highlight {
  border-color: #f1c95b;
  background: #fffaf0;
}

.match-title {
  font-weight: 900;
}

.match-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.group-board {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

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

.guide-card h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.guide-card ul,
.guide-card ol {
  margin: 0;
  padding-left: 1.35em;
}

.guide-card.wide {
  grid-column: 1 / -1;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.mini-table th,
.mini-table td {
  border: 1px solid var(--line);
  padding: 7px;
  text-align: left;
}

.mini-table th {
  background: #f3f6f8;
}

.group-card strong {
  color: var(--green-dark);
}

.group-teams {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.group-team {
  min-height: 34px;
  padding: 5px 8px;
  border-radius: 8px;
  background: #f3f6f8;
  font-size: 14px;
  font-weight: 800;
}

.admin-grid {
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.switch-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 800;
}

.name-row {
  grid-template-columns: 96px minmax(0, 1fr);
  align-items: center;
}

.name-row label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.name-row input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(12px, 3vw, 28px) 26px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 28px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-media {
    width: 100%;
    justify-content: space-between;
  }

  .trophy-board {
    width: min(54vw, 220px);
    height: auto;
    max-height: 132px;
  }

  .summary-band {
    grid-template-columns: 1fr;
  }

  .tabs {
    grid-template-columns: repeat(6, minmax(56px, 1fr));
    overflow-x: auto;
  }

  .tab-button {
    min-width: 58px;
    padding: 0 4px;
    font-size: 13px;
  }

  .section-head,
  .selected-box {
    align-items: stretch;
    flex-direction: column;
  }

  .control-row,
  .action-row,
  .admin-grid {
    align-items: stretch;
    flex-direction: column;
  }

  .field,
  .small-field,
  .compact-field {
    min-width: 0;
    flex: 1 1 auto;
  }

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

  .ranking-card,
  .prize-card,
  .pick-row,
  .match-row,
  .phase-row {
    grid-template-columns: 1fr;
  }

  .prize-board,
  .guide-grid {
    grid-template-columns: 1fr;
  }

  .score {
    font-size: 19px;
  }

  .group-teams {
    grid-template-columns: 1fr;
  }

  .group-team {
    min-height: 38px;
    padding: 7px 9px;
  }
}

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