:root {
  --ink: #172027;
  --muted: #63717c;
  --surface: #f5f7f8;
  --panel: #ffffff;
  --line: #d9e0e5;
  --accent: #126c75;
  --accent-strong: #0c5961;
  --accent-soft: #e1f3f4;
  --gold: #d99b1d;
  --red: #b43e36;
  --blue: #315d9c;
  --shadow: 0 14px 40px rgba(23, 32, 39, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  color: var(--ink);
  background: var(--surface);
}

body {
  min-height: 100vh;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  min-height: 42px;
}

button {
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: #e9eef2;
  cursor: pointer;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

button:hover:not(:disabled) {
  background: #dce5ea;
}

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

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

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(18, 108, 117, 0.22);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

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

.brand-mark {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
}

.brand-mark rect {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-width: 2;
}

.brand-mark path {
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-width: 2.5;
}

.brand-mark circle {
  fill: var(--gold);
  stroke: #8b5f09;
  stroke-width: 2;
}

.brand h1 {
  font-size: 1.45rem;
  line-height: 1.15;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.92rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.selector-link,
.viewer-pill,
.bingo-status {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  font-weight: 900;
  background: #fff;
}

.selector-link {
  text-decoration: none;
}

.primary-button,
.danger-button,
.input-row button {
  padding: 0 16px;
  font-weight: 800;
}

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

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.danger-button {
  color: #fff;
  background: var(--red);
}

.danger-button:hover:not(:disabled) {
  background: #96332d;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(300px, 390px) 1fr;
  gap: 0;
  min-height: 0;
}

.setup-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fff;
  overflow: auto;
}

.control-group {
  display: grid;
  gap: 10px;
}

.control-group label,
.section-heading h2 {
  font-size: 0.88rem;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--muted);
}

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

.section-heading span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.phrase-title-group {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.phrase-list-actions,
.phrase-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.phrase-list-actions button,
.phrase-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.danger-compact,
.phrase-delete {
  color: #fff;
  background: var(--red);
}

.danger-compact:hover:not(:disabled),
.phrase-delete:hover:not(:disabled) {
  background: #96332d;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.game-list,
.phrase-list {
  display: grid;
  gap: 8px;
}

.game-list:empty,
.phrase-list:empty {
  min-height: 48px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fafbfc;
}

.game-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.game-select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  background: #fff;
}

.game-select[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.game-delete {
  align-self: stretch;
  min-width: 76px;
  padding: 0 12px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 900;
  background: var(--red);
}

.game-delete:hover:not(:disabled) {
  background: #96332d;
}

.game-name,
.game-meta {
  display: block;
}

.game-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
}

.game-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.8rem;
}

.form-message {
  min-height: 18px;
  color: var(--red);
  font-size: 0.85rem;
}

.phrase-box {
  min-height: 0;
}

.phrase-list {
  min-height: 0;
  max-height: 310px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.phrase-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.phrase-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.board-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: clamp(16px, 3vw, 32px);
  overflow: auto;
}

.board-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.board-toolbar h2 {
  font-size: 1.3rem;
}

.board-toolbar p {
  margin-top: 4px;
  color: var(--muted);
}

.bingo-status {
  flex: 0 0 auto;
  min-width: 120px;
  box-shadow: var(--shadow);
  cursor: default;
  pointer-events: none;
  user-select: none;
}

.bingo-status.is-win {
  color: #4d3200;
  border-color: #e6bd58;
  background: #fff0bf;
}

.bingo-board {
  width: min(100%, 760px);
  align-self: center;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(6px, 1.5vw, 12px);
}

.bingo-cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 8px 18px rgba(23, 32, 39, 0.06);
  font-size: 0.92rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

.bingo-cell:hover:not(:disabled) {
  border-color: var(--accent);
  background: #f6fcfc;
}

.bingo-cell.is-marked {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.bingo-cell.is-marked::after {
  position: absolute;
  inset: 8px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 6px;
  content: "";
}

.bingo-cell.is-free {
  color: #4d3200;
  border-color: #d7a128;
  background: #fff0bf;
}

.bingo-cell.is-winning {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(217, 155, 29, 0.28);
}

.bingo-cell.is-empty {
  color: var(--muted);
  border-style: dashed;
  background: #f2f5f7;
}

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

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions button,
  .selector-link,
  .viewer-pill {
    flex: 1;
  }

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

  .setup-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .phrase-list {
    max-height: 220px;
  }
}

@media (max-width: 560px) {
  .topbar,
  .setup-panel,
  .board-area {
    padding: 16px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

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

  .bingo-status {
    width: 100%;
  }

  .bingo-cell {
    padding: 6px;
    font-size: 0.72rem;
  }
}
