:root {
  --color-bg-top: #e0f7fa;
  --color-bg-bottom: #fff9c4;
  --color-word: #e91e63;
  --color-counter: #7c4dff;
  --color-instruction: #90a4ae;
  --font-family: "Fredoka", "Nunito", -apple-system, BlinkMacSystemFont,
    sans-serif;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(160deg, var(--color-bg-top), var(--color-bg-bottom));
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.wrapper {
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  padding: env(safe-area-inset-top, 1.5rem) env(safe-area-inset-right, 1.5rem)
    env(safe-area-inset-bottom, 1.5rem) env(safe-area-inset-left, 1.5rem);
}

.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  max-width: 100vw;
  gap: 0.6rem;
}

/* ---- Instruction ---- */
.instruction {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-instruction);
  letter-spacing: 0.03em;
  transition: opacity 0.5s ease;
}

.instruction.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---- Word display ---- */
.title {
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.07);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.title.pop {
  animation: bounce-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounce-in {
  0% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  60% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---- Counter ---- */
#counter {
  font-weight: 600;
  color: var(--color-counter);
  min-height: 1.5em;
  letter-spacing: 0.02em;
}

/* ---- Mobile (default, < 480px) ---- */
.title {
  font-size: clamp(4.5rem, 24vw, 8rem);
}

#counter {
  font-size: 1.2rem;
}

.instruction {
  font-size: 0.9rem;
}

/* ---- Tablet portrait (480px+) ---- */
@media (min-width: 480px) {
  .title {
    font-size: clamp(6rem, 18vw, 12rem);
  }

  #counter {
    font-size: 1.5rem;
  }

  .instruction {
    font-size: 1rem;
  }

  .controls {
    gap: 1rem;
  }

  .control-btn {
    gap: 0.25rem;
    padding: 0.75rem 1.4rem;
    min-width: 6rem;
    border-radius: 1.2rem;
  }

  .btn-icon {
    font-size: 2rem;
  }

  .btn-label {
    font-size: 0.8rem;
  }
}

/* ---- Tablet landscape (768px+) ---- */
@media (min-width: 768px) {
  .menu-toggle {
    width: 3.2rem;
    height: 3.2rem;
    font-size: 1.6rem;
    border-radius: 1rem;
    top: 1rem;
    left: 1rem;
  }

  .sidebar {
    width: 20rem;
  }

  .sidebar-title {
    font-size: 1.3rem;
  }

  .word-list-item {
    padding: 0.85rem 1.5rem;
    font-size: 1.4rem;
  }

  .title {
    font-size: clamp(8rem, 15vw, 16rem);
  }

  #counter {
    font-size: 1.75rem;
  }

  .instruction {
    font-size: 1.1rem;
  }

  .controls {
    gap: 1.25rem;
    padding: 1.25rem;
  }

  .control-btn {
    gap: 0.3rem;
    padding: 1rem 1.75rem;
    min-width: 7.5rem;
    border-radius: 1.3rem;
    border-width: 3.5px;
  }

  .btn-icon {
    font-size: 2.5rem;
  }

  .btn-label {
    font-size: 0.9rem;
  }

  .slider {
    height: 0.6rem;
  }

  .slider::-webkit-slider-thumb {
    width: 1.5rem;
    height: 1.5rem;
  }

  .slider::-moz-range-thumb {
    width: 1.5rem;
    height: 1.5rem;
  }
}

/* ---- Desktop (1024px+) ---- */
@media (min-width: 1024px) {
  .menu-toggle {
    width: 3.5rem;
    height: 3.5rem;
    font-size: 1.8rem;
    border-radius: 1.1rem;
    top: 1.25rem;
    left: 1.25rem;
  }

  .sidebar {
    width: 22rem;
  }

  .word-list-item {
    padding: 1rem 1.75rem;
    font-size: 1.5rem;
  }

  .title {
    font-size: clamp(10rem, 14vw, 22rem);
  }

  #counter {
    font-size: 2rem;
  }

  .controls {
    gap: 1.5rem;
    padding: 1.5rem;
  }

  .control-btn {
    gap: 0.4rem;
    padding: 1.1rem 2rem;
    min-width: 9rem;
    border-radius: 1.4rem;
    border-width: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  }

  .btn-icon {
    font-size: 3rem;
  }

  .btn-label {
    font-size: 1rem;
  }

  .slider {
    height: 0.7rem;
  }

  .slider::-webkit-slider-thumb {
    width: 1.75rem;
    height: 1.75rem;
  }

  .slider::-moz-range-thumb {
    width: 1.75rem;
    height: 1.75rem;
  }
}

/* ---- Large desktop (1440px+) ---- */
@media (min-width: 1440px) {
  .title {
    font-size: clamp(14rem, 12vw, 26rem);
  }

  .controls {
    gap: 2rem;
    padding: 2rem;
  }

  .control-btn {
    gap: 0.5rem;
    padding: 1.3rem 2.5rem;
    min-width: 11rem;
    border-radius: 1.5rem;
    border-width: 4px;
  }

  .btn-icon {
    font-size: 3.5rem;
  }

  .btn-label {
    font-size: 1.15rem;
  }

  .slider {
    height: 0.8rem;
  }

  .slider::-webkit-slider-thumb {
    width: 2rem;
    height: 2rem;
  }

  .slider::-moz-range-thumb {
    width: 2rem;
    height: 2rem;
  }
}

/* ---- Menu toggle button ---- */
.menu-toggle {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 30;
  background: rgba(255, 255, 255, 0.9);
  border: 2.5px solid rgba(0, 0, 0, 0.1);
  border-radius: 0.8rem;
  width: 2.8rem;
  height: 2.8rem;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: var(--font-family);
  color: #555;
  -webkit-user-select: none;
  user-select: none;
  padding: 0;
}

.menu-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

.menu-toggle:active {
  transform: scale(0.93);
}

/* ---- Sidebar overlay ---- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 40;
  transition: opacity 0.25s ease;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 16rem;
  max-width: 80vw;
  z-index: 50;
  background: linear-gradient(180deg, #e8f5e9 0%, #fff9c4 100%);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  font-family: var(--font-family);
  overflow: hidden;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 2px solid rgba(0, 0, 0, 0.08);
}

.sidebar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #2e7d32;
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: #999;
  padding: 0.25rem;
  line-height: 1;
  border-radius: 0.4rem;
  transition: color 0.15s, background 0.15s;
  font-family: var(--font-family);
}

.sidebar-close:hover {
  color: #e53935;
  background: rgba(229, 57, 53, 0.1);
}

.word-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem 0;
  -webkit-overflow-scrolling: touch;
}

.word-list-item {
  padding: 0.7rem 1.25rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  transition: background 0.15s ease;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.word-list-item:hover {
  background: rgba(255, 255, 255, 0.6);
}

.word-list-item:active {
  background: rgba(124, 77, 255, 0.15);
  color: #4a148c;
}

/* ---- Controls bar ---- */
.controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.6rem;
  padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
  z-index: 10;
}

.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  border: 3px solid transparent;
  border-radius: 1.1rem;
  padding: 0.5rem 0.85rem;
  min-width: 4.5rem;
  font-family: var(--font-family);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn-icon {
  font-size: 1.75rem;
  line-height: 1.2;
}

.btn-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.2;
  white-space: nowrap;
}

.control-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.15);
}

.control-btn:active {
  transform: scale(0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Sound button — green / grey */
.btn-sound {
  background: #e8f5e9;
  border-color: #66bb6a;
  color: #2e7d32;
}

.btn-sound.muted {
  background: #f5f5f5;
  border-color: #bdbdbd;
  color: #9e9e9e;
}

/* Voice button — pink/blue */
.btn-voice-pick {
  background: #fce4ec;
  border-color: #f06292;
  color: #c2185b;
}

/* Boy Voice variant */
.btn-voice-pick.boy {
  background: #e3f2fd;
  border-color: #42a5f5;
  color: #1565c0;
}

/* Mix Voices variant */
.btn-voice-pick.mix {
  background: #f3e5f5;
  border-color: #ab47bc;
  color: #7b1fa2;
}

/* Order button — teal */
.btn-order {
  background: #e0f2f1;
  border-color: #26a69a;
  color: #00695c;
}

.btn-order.active {
  background: #b2dfdb;
  border-color: #00897b;
  color: #004d40;
}

/* Mode button — orange / purple when active */
.btn-play {
  background: #fff3e0;
  border-color: #ffa726;
  color: #e65100;
}

.btn-play.active {
  background: #ede7f6;
  border-color: #7c4dff;
  color: #4a148c;
}

/* Speed slider card */
.btn-speed {
  background: #fbe9e7;
  border-color: #ff8a65;
  color: #bf360c;
  cursor: default;
}

.btn-speed:hover {
  transform: none;
}

.btn-speed:active {
  transform: none;
}

#speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 0.5rem;
  border-radius: 0.25rem;
  background: #ffccbc;
  outline: none;
  margin: 0.15rem 0 0;
  cursor: pointer;
}

#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: #ff7043;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

#speed-slider::-moz-range-thumb {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: #ff7043;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

/* Repeat slider card */
.btn-repeat {
  background: #e8eaf6;
  border-color: #7986cb;
  color: #283593;
  cursor: default;
}

.btn-repeat:hover {
  transform: none;
}

.btn-repeat:active {
  transform: none;
}

#repeat-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 0.5rem;
  border-radius: 0.25rem;
  background: #c5cae9;
  outline: none;
  margin: 0.15rem 0 0;
  cursor: pointer;
}

#repeat-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: #5c6bc0;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

#repeat-slider::-moz-range-thumb {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: #5c6bc0;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

/* ---- Landscape phones ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .title {
    font-size: clamp(3rem, 18vh, 6rem);
  }

  #counter {
    font-size: 1rem;
  }

  .instruction {
    font-size: 0.75rem;
  }

  .controls {
    padding: 0.4rem;
  }

  .control-btn {
    padding: 0.3rem 0.6rem;
    border-radius: 0.7rem;
  }

  .btn-icon {
    font-size: 1.1rem;
  }

  .btn-label {
    font-size: 0.55rem;
  }
}
