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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #141414;
  font-family: 'DejaVu Sans', 'Liberation Sans', Arial, sans-serif;
  user-select: none;
  cursor: none;
  touch-action: manipulation;
}

#main {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#emoji-img {
  display: none;
  width: min(58vw, 58vh);
  height: min(58vw, 58vh);
  object-fit: contain;
  image-rendering: auto;
  flex-shrink: 0;
}

#name-text {
  display: none;
  color: #fff;
  font-size: clamp(3.0rem, 10vw, 8rem);
  font-weight: 900;
  text-shadow: 4px 4px 0 #000;
  text-align: center;
  margin-top: 3vh;
  letter-spacing: 0.05em;
}

#letter-display {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: clamp(8rem, 45vh, 22rem);
  font-weight: bold;
  text-shadow: 6px 6px 0 #000;
  line-height: 1;
}

#grid-container {
  display: none;
  gap: clamp(4px, 1.5vmin, 16px);
  padding: clamp(8px, 2vmin, 24px);
  flex: 1;
  width: 100%;
  max-height: 80vh;
  align-content: center;
  justify-items: center;
}

.grid-emoji {
  width: 100%;
  height: 100%;
  max-width: min(20vw, 20vh);
  max-height: min(20vw, 20vh);
  object-fit: contain;
}

.grid-letter {
  color: #fff;
  font-weight: bold;
  text-shadow: 3px 3px 0 #000;
  font-size: clamp(3rem, 10vmin, 8rem);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#grid-word {
  display: none;
  color: #fff;
  font-size: clamp(2.5rem, 8vh, 5rem);
  font-weight: bold;
  text-shadow: 3px 3px 0 #000;
  text-align: center;
  padding: 1vh 0 2vh;
  letter-spacing: 0.05em;
}

#menu {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: clamp(12px, 3vh, 28px);
  background: #141414;
  overflow: hidden;
  position: relative;
}

#menu-title {
  font-size: clamp(2.0rem, 6vmin, 3.6rem);
  font-weight: 900;
  color: #fff;
  text-align: center;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 16px rgba(0,0,0,0.4);
}

#menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(12px, 3.5vmin, 28px);
  width: 100%;
  max-width: min(85vw, 760px);
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.5vw, 20px);
  height: clamp(150px, 30vw, 260px);
  padding: 10px;
  border-radius: 28px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.12s ease;
}

.mode-card.available {
  background: linear-gradient(145deg, var(--card-color) 0%, var(--card-color-dark) 100%);
  box-shadow: 0 8px 32px var(--card-glow), 0 2px 8px rgba(0,0,0,0.3);
  cursor: pointer;
}

.mode-card.available:active {
  transform: scale(0.94);
}

.mode-card.unavailable {
  background: rgba(255,255,255,0.07);
  opacity: 0.4;
  pointer-events: none;
}

.mode-card-emoji {
  font-size: clamp(3.2rem, 9vmin, 6rem);
  line-height: 1;
}

.mode-card-name {
  font-size: clamp(1.0rem, 2.6vmin, 1.4rem);
  font-weight: 700;
  color: #fff;
  text-align: center;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.mode-card-badge {
  font-size: clamp(0.6rem, 1.4vmin, 0.8rem);
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#back-btn {
  position: fixed;
  top: 10px;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  left: calc(10px + env(safe-area-inset-left));
  width: 44px;
  height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: rgba(255,255,255,0.35);
  background: none;
  border: none;
  border-radius: 50%;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, background 0.2s;
  z-index: 210;
  font-family: inherit;
  cursor: default;
}

#back-btn.pressing {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.15);
}

#settings-update-btn {
  background: #FF6B35;
  color: #fff;
  border: none;
  border-radius: 18px;
  font-size: clamp(1.1rem, 3vmin, 1.6rem);
  font-weight: 700;
  padding: clamp(14px, 3vh, 24px) clamp(28px, 6vw, 48px);
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 6px 24px rgba(255,107,53,0.4);
}

#settings-update-btn:disabled {
  opacity: 0.5;
}

#settings-build {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.35);
  font-family: monospace;
}

#settings-back-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.6);
  border-radius: 12px;
  font-size: 1rem;
  padding: 10px 24px;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: min(90vw, 520px);
  background: rgba(255,255,255,0.04);
  padding: 20px;
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.06);
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  width: 100%;
}

.settings-label {
  color: rgba(255,255,255,0.7);
  font-size: 1.05rem;
  font-weight: 700;
  font-family: sans-serif;
}

.settings-options {
  display: flex;
  gap: 8px;
  width: 100%;
}

.settings-opt-btn {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 2px solid transparent;
  color: rgba(255,255,255,0.85);
  border-radius: 14px;
  padding: 12px 4px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.settings-opt-btn.active {
  background: #FFD43B;
  color: #141414;
  box-shadow: 0 4px 16px rgba(255,212,59,0.35);
  border-color: #FFD43B;
}

#menu-settings-btn {
  position: fixed;
  bottom: 0px;
  bottom: env(safe-area-inset-bottom);
  right: 0px;
  right: env(safe-area-inset-right);
  width: 60px;
  height: 60px;
  background: none;
  border: none;
  font-size: 1.6rem;
  opacity: 0.25;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  -webkit-tap-highlight-color: transparent;
}

#pw-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#pw-box {
  background: #222;
  border-radius: 20px;
  padding: 28px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 260px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

#pw-input {
  background: #333;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  color: #fff;
  font-size: 1.1rem;
  padding: 12px 16px;
  outline: none;
  font-family: inherit;
  width: 100%;
}

#pw-btn-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

#pw-cancel {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.6);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
}

#pw-ok {
  background: #FF6B35;
  border: none;
  color: #fff;
  border-radius: 10px;
  padding: 10px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

#paint-container {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

#paint-wrapper {
  position: relative;
  width: min(58vw, 58vh);
  height: min(58vw, 58vh);
  flex-shrink: 0;
}

#paint-emoji-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

#paint-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  -webkit-filter: grayscale(100%) brightness(65%) contrast(0.35);
  filter: grayscale(100%) brightness(65%) contrast(0.35);
  opacity: 0.96;
}

#paint-name-text {
  display: none;
  position: absolute;
  bottom: 15vh;
  left: 0;
  width: 100%;
  color: #fff;
  font-size: clamp(3.0rem, 10vw, 8rem);
  font-weight: 900;
  text-shadow: 4px 4px 0 #000;
  text-align: center;
  letter-spacing: 0.05em;
  user-select: none;
  z-index: 100;
  pointer-events: none;
}

#paint-slider-container {
  position: absolute;
  bottom: 6vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 150;
  user-select: none;
  -webkit-user-select: none;
}

#paint-slider-track {
  position: relative;
  width: min(80vw, 360px);
  height: 60px;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#paint-slider-text {
  color: rgba(255,255,255,0.65);
  font-size: 1.1rem;
  font-weight: 700;
  font-family: sans-serif;
  pointer-events: none;
  letter-spacing: 0.02em;
}

#paint-slider-handle {
  position: absolute;
  left: 4px;
  width: 52px;
  height: 52px;
  background: #FFD43B;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  cursor: grab;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: transform 0.1s ease-out;
  touch-action: none;
}

#paint-slider-handle:active {
  cursor: grabbing;
}

.star-particle {
  position: fixed;
  font-size: clamp(1.5rem, 4vmin, 3rem);
  pointer-events: none;
  z-index: 150;
  user-select: none;
  animation: explode-star 1.5s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes explode-star {
  0% {
    transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.5) rotate(720deg);
    opacity: 0;
  }
}
