:root {
  color-scheme: light dark;
  --font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --heading-font: "Inter", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --bg: #101218;
  --bg-gradient: radial-gradient(circle at top, #181a23 0%, #101218 60%);
  --panel-bg: rgba(17, 19, 26, 0.82);
  --fg: #f4f4f8;
  --muted: #c6cad6;
  --accent: #536dfe;
  --accent-soft: rgba(83, 109, 254, 0.15);
  --green: #35c759;
  --orange: #f6a609;
  --gray: #3c414f;
  --border: rgba(255, 255, 255, 0.09);
  --tile-border: rgba(255, 255, 255, 0.2);
  --tile-bg: rgba(255, 255, 255, 0.04);
  --key-bg: rgba(255, 255, 255, 0.07);
  --key-absent-bg: rgba(10, 12, 18, 0.9);
  --key-absent-fg: rgba(255, 255, 255, 0.38);
  --key-absent-border: rgba(255, 255, 255, 0.12);
  --tile-size: clamp(48px, 11vw, 64px);
}

:root[data-theme="aurora"] {
  --font-family: "Sora", "Inter", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --heading-font: "Sora", "Inter", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --bg: #071625;
  --bg-gradient: radial-gradient(circle at top, #123054 0%, #070d16 70%);
  --panel-bg: rgba(8, 18, 34, 0.86);
  --fg: #e6f7ff;
  --muted: #9eb7d5;
  --accent: #36d7ff;
  --accent-soft: rgba(54, 215, 255, 0.16);
  --green: #4df3c2;
  --orange: #fed766;
  --gray: #1b2f45;
  --border: rgba(102, 195, 255, 0.18);
  --tile-border: rgba(102, 195, 255, 0.22);
  --tile-bg: rgba(255, 255, 255, 0.06);
  --key-bg: rgba(255, 255, 255, 0.08);
  --key-absent-bg: rgba(7, 20, 37, 0.94);
  --key-absent-fg: rgba(198, 231, 255, 0.5);
  --key-absent-border: rgba(102, 195, 255, 0.18);
}

:root[data-theme="sunset"] {
  --font-family: "Space Grotesk", "Inter", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  --heading-font: "Space Grotesk", "Inter", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #1b0b0f;
  --bg-gradient: radial-gradient(circle at top, #431c2b 0%, #12060a 70%);
  --panel-bg: rgba(34, 13, 20, 0.86);
  --fg: #ffe9dc;
  --muted: #f3b8a9;
  --accent: #ff8777;
  --accent-soft: rgba(255, 135, 119, 0.18);
  --green: #65e4b7;
  --orange: #ffc862;
  --gray: #3b1f2b;
  --border: rgba(255, 135, 119, 0.22);
  --tile-border: rgba(255, 255, 255, 0.2);
  --tile-bg: rgba(255, 255, 255, 0.08);
  --key-bg: rgba(255, 235, 220, 0.12);
  --key-absent-bg: rgba(42, 18, 26, 0.95);
  --key-absent-fg: rgba(255, 224, 214, 0.52);
  --key-absent-border: rgba(255, 135, 119, 0.24);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg-gradient);
  color: var(--fg);
  display: flex;
  justify-content: center;
  align-items: stretch;
  font-family: var(--font-family);
}

.app {
  width: min(96vw, 480px);
  margin: 3vh auto;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  backdrop-filter: blur(16px);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  min-height: 580px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
}

.app-title {
  font-size: clamp(1.6rem, 2.4vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.1em;
  margin: 0;
  font-family: var(--heading-font);
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.new-game-button {
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
}

.new-game-button:hover,
.new-game-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  opacity: 0.95;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.36);
}

.hint-button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.icon-button {
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.12);
}

.icon {
  font-size: 1.1rem;
}

.icon-gear {
  font-size: 1.3rem;
}

.game {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 12px 24px 28px;
  gap: 20px;
  min-height: 0;
}

.board-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.board {
  display: grid;
  gap: 8px;
  justify-content: center;
  width: min(100%, 420px);
  margin: 0 auto;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 12px;
  border: 1px solid var(--tile-border);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(1.4rem, 3.8vw, 2.05rem);
  font-weight: 600;
  text-transform: uppercase;
  background: var(--tile-bg);
  color: var(--fg);
  transition: transform 0.2s ease, background 0.3s ease, border 0.3s ease,
    color 0.3s ease;
}

.tile.filled {
  border-color: rgba(255, 255, 255, 0.55);
}

.tile.revealed {
  animation: flip 0.6s ease forwards;
}

.tile.correct {
  background: var(--green);
  border-color: var(--green);
  color: #101218;
}

.tile.present {
  background: var(--orange);
  border-color: var(--orange);
  color: #101218;
}

.tile.absent {
  background: var(--gray);
  border-color: var(--gray);
  color: #eef0f6;
}

@keyframes flip {
  0% {
    transform: rotateX(0deg);
  }
  50% {
    transform: rotateX(-90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.tile.bump {
  animation: pop 0.16s ease;
}

.tile.shake {
  animation: shake 0.28s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5%);
  }
  50% {
    transform: translateX(4%);
  }
  75% {
    transform: translateX(-3%);
  }
}

.message {
  min-height: 0;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
  transition: opacity 0.3s ease;
  opacity: 0;
}

.message.show {
  opacity: 1;
  min-height: 24px;
}

.status-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: 100%;
}

.hint-display {
  display: none;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
  width: 100%;
  margin-top: 0;
}

.hint-display.show {
  display: block;
}

.message.show + .hint-display {
  margin-top: 4px;
}

.keyboard {
  display: grid;
  gap: 8px;
}

.keyboard-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 8px;
}

.key {
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--key-bg);
  color: var(--fg);
  padding: 12px 0;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
  flex: 1 1 0;
  min-width: 0;
}

.key:hover,
.key:focus-visible {
  outline: none;
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
}

.key--enter {
  flex: 1.45 1 0;
  font-size: 0.85rem;
}

.key--back {
  flex: 0.8 1 0;
  font-size: 1.2rem;
  padding-left: 0;
  padding-right: 0;
}

.key.correct {
  background: var(--green);
  color: #101218;
}

.key.present {
  background: var(--orange);
  color: #101218;
}

.key.absent {
  background: var(--key-absent-bg);
  color: var(--key-absent-fg);
  border-color: var(--key-absent-border);
}

.modal {
  border: 1px solid var(--border);
  padding: 0;
  border-radius: 18px;
  background: var(--panel-bg);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.4);
  color: var(--fg);
  width: min(92vw, 420px);
  backdrop-filter: blur(14px);
}

.modal::backdrop {
  background: rgba(4, 6, 12, 0.6);
}

.modal-content {
  display: flex;
  flex-direction: column;
}

.modal-header,
.modal-footer {
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
}

.modal-body {
  padding: 24px;
  display: grid;
  gap: 20px;
}

.field {
  display: grid;
  gap: 8px;
}

.field-label {
  font-weight: 500;
}

.field-help {
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="number"] {
  appearance: none;
  border-radius: 12px;
  border: 1px solid var(--tile-border);
  background: rgba(255, 255, 255, 0.04);
  padding: 12px 14px;
  color: var(--fg);
  font-size: 1rem;
  font-weight: 500;
}

input[type="number"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select {
  border-radius: 12px;
  border: 1px solid var(--tile-border);
  background: rgba(255, 255, 255, 0.04);
  padding: 12px 14px;
  color: var(--fg);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.segment {
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

.primary-button {
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 24px;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.primary-button:hover,
.primary-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  opacity: 0.9;
}

.danger-button {
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #fd4766, #fc6a3f);
  color: #fff;
  font-weight: 600;
  padding: 12px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
  width: 100%;
  text-align: center;
}

.danger-button:hover,
.danger-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  opacity: 0.9;
}

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

.theme-option {
  border: 1px solid var(--tile-border);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--tile-bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  transition: transform 0.2s ease, border 0.2s ease, background 0.2s ease;
}

.theme-option .theme-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.theme-option:hover,
.theme-option:focus-visible {
  outline: none;
  transform: translateY(-1px);
  border-color: var(--accent);
}

.theme-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.theme-swatch {
  display: flex;
  width: 100%;
  height: 28px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--tile-border);
}

.theme-swatch--midnight {
  background: linear-gradient(135deg, #1a1f2a 0%, #0f1119 100%);
}

.theme-swatch--aurora {
  background: linear-gradient(135deg, #00d2ff 0%, #3a47d5 100%);
}

.theme-swatch--sunset {
  background: linear-gradient(135deg, #ff7e5f 0%, #feb47b 100%);
}

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

.stat {
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 14px;
  padding: 16px;
  display: grid;
  gap: 4px;
  text-align: center;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 600px) {
  .app {
    width: 100vw;
    margin: 0;
    border-radius: 0;
    min-height: 100svh;
  }

  .app-header {
    padding: 14px 16px 10px;
    gap: 8px;
  }

  .app-title {
    font-size: clamp(1.3rem, 5vw, 1.6rem);
    letter-spacing: 0.08em;
  }

  .new-game-button {
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .game {
    padding: 12px 16px 18px;
    gap: 14px;
  }

  .board {
    gap: 6px;
  }

  .keyboard-row {
    gap: 6px;
  }

  .key {
    padding: 10px 0;
    font-size: 0.9rem;
  }

  .key--enter {
    flex: 1.35 1 0;
  }

  .key--back {
    flex: 0.75 1 0;
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 12px 14px 8px;
  }

  .header-actions {
    gap: 8px;
  }

  .new-game-button {
    padding: 7px 12px;
    font-size: 0.8rem;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }
}

@media (max-height: 740px) {
  .app {
    min-height: 100vh;
  }

  .app-header {
    padding-bottom: 6px;
  }

  .game {
    padding: 10px 14px 14px;
    gap: 12px;
  }

  .board {
    gap: 5px;
  }

  .keyboard-row {
    gap: 5px;
  }

  .key {
    padding: 9px 0;
    font-size: 0.85rem;
  }

  .key--enter {
    flex: 1.3 1 0;
    font-size: 0.8rem;
  }

  .key--back {
    flex: 0.7 1 0;
    font-size: 1.05rem;
  }
}
