:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --ink: #17211b;
  --muted: #657067;
  --line: #d9ded9;
  --accent: #d83131;
  --accent-ink: #ffffff;
  --green: #197b45;
  --yellow: #b7791f;
  --shadow: 0 12px 32px rgba(23, 33, 27, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a {
  color: inherit;
  overflow-wrap: anywhere;
}

button,
.button-link {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

button.primary,
.button-link.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

button.ghost {
  background: transparent;
}

button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.88rem;
}

button.big {
  min-height: 54px;
  width: 100%;
  font-size: 1.05rem;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

label input,
label select {
  color: var(--ink);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

main {
  width: 100%;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: rgba(246, 247, 244, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 800;
  text-decoration: none;
}

.topbar nav {
  display: flex;
  min-width: 0;
  gap: 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar nav a {
  white-space: nowrap;
}

.flash-stack {
  position: fixed;
  top: 68px;
  right: 16px;
  z-index: 20;
  display: grid;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
}

.flash-message {
  margin: 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.flash-message.error {
  border-left-color: var(--accent);
}

.section-band {
  width: 100%;
  min-width: 0;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.section-band.narrow,
.auth-panel {
  max-width: 980px;
  margin: 32px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel {
  max-width: 420px;
  padding: 24px;
}

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

.section-heading h1,
.section-heading h2 {
  margin: 0;
}

.section-heading span,
.muted {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

.inline-form,
.action-row {
  display: flex;
  min-width: 0;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.grow {
  flex: 1 1 260px;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.checkbox-line input {
  width: auto;
  min-height: auto;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.compact th,
.table-wrap.compact td {
  padding: 7px 8px;
  font-size: 0.88rem;
}

.csv-example {
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  background: #17211b;
  color: #f6f7f4;
  overflow-x: auto;
}

.admin-shell {
  display: grid;
  min-width: 0;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 56px);
}

.admin-nav {
  position: sticky;
  top: 56px;
  align-self: start;
  height: calc(100vh - 56px);
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  min-width: 0;
  align-content: start;
  gap: 10px;
}

.admin-nav h1 {
  margin: 0 0 10px;
}

.admin-nav a {
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.admin-nav a:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.admin-content {
  min-width: 0;
}

.round-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  align-items: end;
}

.timer-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.timer-strip strong {
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 1;
}

.timer-strip[data-state="phase2"],
.timer-hero[data-state="phase2"] {
  border-color: var(--yellow);
}

.timer-strip[data-state="finished"],
.timer-hero[data-state="finished"] {
  border-color: var(--accent);
  background: #fff0f0;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.room-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  min-width: 0;
}

.room-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.room-card h3,
.room-card h4 {
  margin: 0 0 10px;
}

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

.result-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

select.conflict {
  border-color: var(--accent);
  background: #fff7f0;
}

.closed {
  background: var(--surface-2);
  color: var(--muted);
}

.player-shell {
  width: min(760px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  gap: 14px;
}

.player-header {
  display: flex;
  min-width: 0;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.player-header h1 {
  margin: 0;
  font-size: clamp(1.5rem, 8vw, 2.4rem);
}

.player-header p {
  margin: 4px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.sound-banner,
.player-block,
.room-hero,
.timer-hero {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  min-width: 0;
}

.sound-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.player-block h2 {
  margin: 0 0 10px;
}

.room-hero,
.timer-hero {
  display: grid;
  gap: 8px;
}

.room-hero span,
.timer-hero span {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 800;
}

.room-hero strong,
.timer-hero strong {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(4rem, 28vw, 9rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.room-hero p {
  margin: 0;
  font-size: 1.05rem;
}

.points {
  margin: 0;
  font-size: 4rem;
  line-height: 1;
  font-weight: 850;
}

.prose {
  font-size: 1.05rem;
}

.prose img {
  max-width: 100%;
  border-radius: 8px;
}

.timer-flash {
  animation: flash-bg 0.6s linear 3;
}

@keyframes flash-bg {
  0%,
  100% {
    background: var(--bg);
  }
  50% {
    background: #ffd9d9;
  }
}

@media (max-width: 840px) {
  .topbar {
    padding: 0 14px;
  }

  .topbar nav {
    gap: 9px;
    font-size: 0.86rem;
  }

  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-nav {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    grid-template-columns: repeat(5, auto);
    overflow-x: auto;
    max-width: 100vw;
  }

  .admin-nav h1,
  .admin-nav form {
    display: none;
  }

  .section-band {
    padding: 18px 14px;
  }

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

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

@media (max-width: 520px) {
  .topbar {
    align-items: start;
    gap: 6px;
    min-height: 0;
    padding: 8px 12px;
  }

  .topbar nav {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 4px;
  }

  button,
  .button-link {
    max-width: 100%;
    white-space: normal;
    text-align: center;
  }

  input[type="file"] {
    font-size: 0.86rem;
  }

  .section-heading,
  .player-header {
    display: grid;
  }

  .inline-form,
  .action-row {
    width: 100%;
    align-items: stretch;
  }

  .inline-form > *,
  .action-row > * {
    max-width: 100%;
  }

  .round-grid,
  .result-row {
    grid-template-columns: 1fr;
  }

  .room-hero strong,
  .timer-hero strong {
    font-size: clamp(4rem, 26vw, 6.5rem);
  }
}
