:root {
  --bg: #eef2ff;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --border: #d1d5db;
  --danger: #b91c1c;
  --shadow: 0 16px 45px rgba(31, 41, 55, 0.12);
  --radius: 20px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #ffffff 0, var(--bg) 42%, #dbeafe 100%);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior: none;
}

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

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.2rem);
  letter-spacing: -0.05em;
}

h2 {
  font-size: 1.25rem;
  margin-bottom: 14px;
}

.tagline,
.status-text {
  color: var(--muted);
  margin: 4px 0 0;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(209, 213, 219, 0.75);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
}

.setup-grid,
.settings-row,
.button-row,
.game-title-row,
.guess-area {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.setup-grid label,
.settings-row label {
  flex: 1;
  min-width: 150px;
}

label {
  font-weight: 700;
  font-size: 0.9rem;
  color: #374151;
}

input,
select {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 16px;
  background: white;
  touch-action: manipulation;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 50px;
}

.toggle-line input {
  width: auto;
  margin: 0;
  transform: scale(1.25);
}

button {
  border: 0;
  background: var(--primary);
  color: white;
  border-radius: 999px;
  padding: 11px 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:hover {
  transform: translateY(-1px);
  background: var(--primary-dark);
}

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

.ghost {
  background: #eef2ff;
  color: var(--primary-dark);
  border: 1px solid #c7d2fe;
}

.secondary {
  background: #111827;
}

.danger {
  color: var(--danger);
  border-color: #fecaca;
  background: #fff1f2;
}

.submit {
  width: 100%;
  margin-top: 14px;
}

.hidden {
  display: none !important;
}

.game-title-row {
  justify-content: space-between;
  align-items: start;
}

.slots {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
}

.slot,
.color-btn,
.peg-dot {
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  border: 3px solid rgba(31, 41, 55, 0.14);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.slot {
  width: clamp(48px, 14vw, 62px);
  height: clamp(48px, 14vw, 62px);
  background: #f3f4f6;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.08);
}

.slot.empty::after {
  content: "+";
  color: #9ca3af;
  font-size: 1.7rem;
  font-weight: 800;
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.color-btn {
  width: 100%;
  aspect-ratio: 1;
  min-height: 46px;
  box-shadow: 0 8px 18px rgba(31, 41, 55, 0.16);
}

.color-btn:hover {
  transform: translateY(-2px) scale(1.02);
}

.board-wrap {
  overflow: auto;
  margin-top: 18px;
  margin-bottom: 18px;
  max-height: 52vh;
  border-radius: 14px;
  border: 1px solid var(--border);
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.board {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th,
td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}

th {
  background: #f9fafb;
  position: sticky;
  top: 0;
  z-index: 1;
  color: #4b5563;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.guess-dots,
.result-dots {
  display: flex;
  gap: 7px;
  align-items: center;
}

.mini-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.12);
  display: inline-block;
}

.peg-dot {
  width: 22px;
  height: 22px;
  border-width: 2px;
}

.black-peg {
  background: #111827;
}

.white-peg {
  background: #fff;
}

.message-card {
  font-size: 1.05rem;
  scroll-margin-top: 12px;
}

.message-card strong {
  color: var(--primary-dark);
}

dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  max-width: 520px;
  width: calc(100% - 32px);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-card {
  padding: 20px;
}

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

.stat {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 12px;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
}

.stat strong {
  font-size: 1.35rem;
}

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

  .palette {
    grid-template-columns: repeat(3, 1fr);
  }

  .game-title-row,
  .guess-area {
    align-items: center;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .mini-dot {
    width: 23px;
    height: 23px;
  }

  .peg-dot {
    width: 18px;
    height: 18px;
  }
}
