* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 15% 20%, #2c2a4f 0%, rgba(44, 42, 79, 0) 35%),
    radial-gradient(circle at 85% 0%, #15305c 0%, rgba(21, 48, 92, 0) 40%),
    #10111a;
  color: #f8f8fc;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1.1rem 2rem;
  display: grid;
  gap: 1rem;
}

.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: 0.02em;
  text-shadow: 0 4px 20px rgba(72, 122, 255, 0.28);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.icon-btn {
  background: rgba(79, 124, 255, 0.14);
  border: 1px solid rgba(180, 190, 255, 0.3);
  border-radius: 999px;
  color: #f1f2ff;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

.icon-btn:hover {
  background: rgba(79, 124, 255, 0.28);
  transform: translateY(-1px);
}

.subtitle {
  margin: 0.5rem 0;
  color: #d9d9ea;
}

.attempts {
  margin: 0.25rem 0 1rem;
  font-weight: 700;
  color: #f5f5ff;
}

.board-section,
.palette-section,
.history-section,
.result-section {
  background: rgba(23, 24, 36, 0.78);
  border: 1px solid rgba(180, 190, 255, 0.18);
  border-radius: 14px;
  padding: 1rem;
  backdrop-filter: blur(4px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
}

.board-section h2,
.palette-section h2,
.history-section h2 {
  margin: 0 0 0.75rem;
}

.flag-board {
  border: 2px solid rgba(220, 226, 255, 0.9);
  border-radius: 12px;
  overflow: hidden;
  width: min(100%, 820px);
  aspect-ratio: 2 / 1;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 0 0 1px rgba(20, 20, 28, 0.2);
}

.stripe-row {
  display: flex;
  flex: 1;
}

.stripe-feedback {
  width: 2.25rem;
  min-width: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f1014;
  border-left: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  font-weight: 900;
  font-size: 1.1rem;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.stripe-row:last-child .stripe-feedback {
  border-bottom: none;
}

.feedback-correct {
  color: #46d275;
}

.feedback-shade {
  color: #ff8f3d;
}

.feedback-present {
  color: #f0c64f;
}

.feedback-absent {
  color: #ff4d57;
}

.feedback-empty {
  color: #555762;
}

.stripe-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: auto;
  flex: 1;
  border: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.22);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: filter 0.14s ease;
}

.stripe-btn:hover {
  filter: brightness(1.04);
}

.stripe-locked {
  cursor: not-allowed;
  box-shadow: inset 0 0 0 3px rgba(82, 211, 142, 0.75);
}

#app-root[inert] {
  filter: blur(1.5px) brightness(0.8);
}

.stripe-btn:last-child {
  border-bottom: none;
}

.stripe-row:last-child .stripe-btn {
  border-bottom: none;
}

.stripe-template-even {
  background: #c9c9ca;
}

.stripe-template-odd {
  background: #f2f2f2;
}

.palette {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.55rem;
}

.palette-row {
  display: grid;
  gap: 0.35rem;
}

.palette-swatch-line {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.28rem;
}

.color-btn {
  border: 2px solid #6f7393;
  border-radius: 5px;
  color: transparent;
  padding: 0;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 34px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.color-btn:hover {
  transform: translateY(-1px);
}

.color-btn:focus-visible,
.stripe-btn:focus-visible,
button:focus-visible {
  outline: 3px solid #ffe98f;
  outline-offset: 2px;
}

.color-btn.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(136, 153, 255, 0.45);
}

.active-color {
  margin-top: 0.6rem;
  color: #f1f2ff;
  font-weight: 600;
}

.controls {
  margin: 0.1rem 0 0.2rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.controls button {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 0.62rem 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.controls button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

#submit-btn {
  background: #4f7cff;
  color: white;
}

#clear-btn {
  background: #6d6d74;
  color: white;
}

#hint-btn {
  background: #b07a1a;
  color: white;
}

#hint-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

#new-game-btn {
  background: #1f9a70;
  color: white;
}

.stripe-hinted {
  box-shadow: inset 0 0 0 2px rgba(255, 199, 89, 0.85);
}

.stripe-hint-badge {
  pointer-events: none;
  font-size: clamp(0.65rem, 1.8vw, 0.85rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #111111;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.85);
  background: rgba(255, 236, 170, 0.72);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.7rem;
}

.history-row-card {
  display: grid;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(170, 179, 255, 0.22);
  background: rgba(21, 23, 37, 0.7);
}

.history-guess-label {
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #bcc2ee;
  font-weight: 700;
}

.history-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  padding: 0.38rem 0.52rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.83rem;
  line-height: 1.2;
  border: 2px solid transparent;
  color: #101013;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.12);
}

.chip-status-correct {
  border-color: #52d38e;
}

.chip-status-present {
  border-color: #f0c64f;
}

.chip-status-shade {
  border-color: #ff8f3d;
}

.chip-status-absent {
  border-color: #696970;
}

.result-message {
  margin-top: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #f2f3ff;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 90;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 16, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fadeIn 0.18s ease;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: linear-gradient(160deg, #232544, #171827);
  border: 1px solid rgba(180, 190, 255, 0.35);
  border-radius: 18px;
  padding: 2rem 2.5rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: popIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.modal--wide {
  max-width: 480px;
  text-align: left;
}

.modal-title {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(90deg, #52d38e, #4f7cff, #ff6b9f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal-title--help {
  font-size: 1.7rem;
  background: linear-gradient(90deg, #4f7cff, #8e6bff);
  -webkit-background-clip: text;
  background-clip: text;
}

.modal--lose {
  border-color: rgba(255, 130, 130, 0.35);
}

.modal-title--lose {
  background: linear-gradient(90deg, #ff6b6b, #ff9f43);
  -webkit-background-clip: text;
  background-clip: text;
}

.modal--lose button:not(.modal-secondary-btn) {
  background: #ff6b6b;
}

.modal-subtitle {
  margin: 0.6rem 0 1rem;
  color: #dfe1ff;
  font-weight: 600;
  text-align: center;
}

.modal-body {
  text-align: left;
  color: #e4e6ff;
  line-height: 1.5;
}

.help-body ul {
  margin: 0.4rem 0 0.9rem;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.35rem;
}

.modal-flag-preview {
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
  height: 90px;
  margin: 0 auto 1.2rem;
  max-width: 260px;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.modal-flag-stripe {
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
}

.modal button {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1.4rem;
  font-weight: 700;
  cursor: pointer;
  background: #4f7cff;
  color: white;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease;
}

.modal button:hover {
  transform: translateY(-1px);
}

.modal-secondary-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #f1f2ff;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0.5rem 0 1.2rem;
}

.stats-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stats-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: #ffffff;
}

.stats-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #b9bfec;
}

.stats-subheading {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  color: #e4e6ff;
}

.stats-distribution {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.2rem;
}

.stats-bar-row {
  display: grid;
  grid-template-columns: 1.2rem 1fr;
  align-items: center;
  gap: 0.5rem;
}

.stats-bar-label {
  font-weight: 700;
  color: #d9d9ea;
  text-align: right;
}

.stats-bar-track {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  height: 1.3rem;
}

.stats-bar-fill {
  background: linear-gradient(90deg, #4f7cff, #52d38e);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.35rem;
  height: 100%;
  min-width: 1.4rem;
  transition: width 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal {
    animation: none;
  }

  .controls button:hover,
  .color-btn:hover,
  .modal button:hover {
    transform: none;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 1rem 0.75rem 1.5rem;
    gap: 0.75rem;
  }

  .app-header-top {
    justify-content: center;
    text-align: center;
  }

  .app-header h1 {
    width: 100%;
    text-align: center;
  }

  .controls {
    justify-content: center;
  }

  .controls button {
    flex: 1 1 auto;
    min-width: 0;
  }

  .stripe-feedback {
    width: 1.7rem;
    min-width: 1.7rem;
    font-size: 0.95rem;
  }

  .color-btn {
    max-width: none;
  }

  .stats-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal {
    padding: 1.5rem 1.25rem;
  }

  .modal-title {
    font-size: 1.9rem;
  }
}

@media (max-width: 400px) {
  .header-actions {
    width: 100%;
    justify-content: center;
  }

  .stripe-feedback {
    width: 1.4rem;
    min-width: 1.4rem;
    font-size: 0.8rem;
  }
}
