:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --page-bg: #f3f4f6;
  --panel-bg: #ffffff;
  --ink: #111827;
  --muted: #5b6472;
  --line: #d1d5db;
  --focus: #0f766e;
  --danger: #b91c1c;
  --shadow: 0 12px 34px rgba(17, 24, 39, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  min-height: 100vh;
  padding: 14px 14px 112px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.top-bar,
.selected-tools,
.import-panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.06);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

h1 {
  margin: 0;
  line-height: 1;
}

.game-title,
.selected-name-input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-weight: 900;
}

.game-title {
  max-width: min(62vw, 580px);
  padding: 3px 0;
  font-size: clamp(1.35rem, 4vw, 2.2rem);
  line-height: 1.05;
}

.game-title:focus,
.selected-name-input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  background: #eef2f7;
}

.status-text {
  min-height: 1.2em;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.top-actions,
.import-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button,
.utility-button,
.score-controls button {
  min-height: 44px;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  width: 48px;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}

.utility-button {
  padding: 0 14px;
  font-weight: 700;
}

.players-grid {
  flex: 1;
  min-height: 360px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  grid-auto-rows: minmax(170px, 1fr);
  gap: 10px;
}

.player-tile {
  container-type: inline-size;
  position: relative;
  width: 100%;
  min-width: 0;
  border: 4px solid transparent;
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
}

.player-tile.selected {
  border-color: var(--focus);
  outline: 4px solid rgba(15, 118, 110, 0.24);
}

.player-name {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  text-align: center;
  font-size: clamp(1.5rem, 5vw, 3.1rem);
  font-weight: 800;
  line-height: 1.05;
}

.player-name:focus {
  outline: 3px solid currentColor;
  background: rgba(255, 255, 255, 0.28);
}

.player-score {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 6px;
  padding: 0 4px;
  background: transparent;
  color: inherit;
  text-align: center;
  font-size: clamp(1.25rem, 16vw, 10rem);
  font-size: clamp(1.25rem, min(16vw, calc(112cqw / var(--score-chars, 1))), 10rem);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
}

.player-score:focus {
  outline: 3px solid currentColor;
  background: rgba(255, 255, 255, 0.22);
}

.selected-tools {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.selected-heading {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.selected-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.selected-name-input {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 1.1rem;
  line-height: 1.2;
  padding: 4px 6px;
}

.selected-tools label {
  display: grid;
  grid-template-columns: auto 46px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input[type="color"] {
  width: 46px;
  height: 44px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.import-panel {
  padding: 12px;
  display: grid;
  gap: 10px;
}

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

.file-picker {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  background: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
}

.error-text {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

.score-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 28px rgba(17, 24, 39, 0.12);
}

.score-controls button {
  min-width: 0;
  min-height: 68px;
  background: #111827;
  color: #ffffff;
  border-color: #111827;
  font-size: clamp(1rem, 3.8vw, 1.7rem);
  font-weight: 900;
}

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

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

@media (max-width: 760px) {
  .top-bar,
  .selected-tools {
    align-items: stretch;
    grid-template-columns: 1fr 1fr;
  }

  .top-bar {
    flex-direction: column;
  }

  .top-bar > div,
  .game-title {
    max-width: 100%;
    width: 100%;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > *,
  .selected-tools > *,
  .import-row > * {
    flex: 1;
  }

  .selected-tools {
    display: grid;
  }

  .selected-heading {
    grid-column: 1 / -1;
  }

  .selected-tools label {
    grid-template-columns: 1fr 46px;
  }

  .selected-tools .utility-button {
    width: 100%;
  }

  .score-controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .score-controls button {
    min-height: 56px;
  }

  .app-shell {
    padding-bottom: 148px;
  }
}

@media (min-width: 900px) {
  .players-grid {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  }
}
