/* ─── Variables ──────────────────────────────────────────── */
:root {
  --blue: #3d88e8;
  --blue-dark: #2a6bc7;
  --green: #27ae60;
  --red: #e74c3c;
  --bg: #f0f6ff;
  --white: #ffffff;
  --tile-border: #bcd4f5;
  --tile-size: 64px;
  --box-size: 74px;
  --radius: 14px;
  --shadow: 0 4px 14px rgba(0,0,0,0.12);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: #1a1a2e;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* ─── Screens ────────────────────────────────────────────── */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 36px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.96); }

.btn-primary  { background: var(--blue); color: #fff; }
.btn-ghost    { background: rgba(255,255,255,0.28); color: #fff; border: 2px solid rgba(255,255,255,0.5); }
.btn-text     { background: none; color: #888; font-size: 1rem; padding: 12px; }

.btn-icon {
  background: rgba(0,0,0,0.08);
  border: none;
  border-radius: 50%;
  width: 42px; height: 42px;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.toggle {
  padding: 10px 18px;
  border: 2px solid var(--tile-border);
  background: var(--white);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: #555;
  transition: all 0.15s;
  -webkit-user-select: none;
}
.toggle.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

/* ─── Splash ─────────────────────────────────────────────── */
#screen-splash {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #3d88e8 0%, #6fa8f5 100%);
}
.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 52px;
}
.app-title {
  text-align: center;
  font-size: 3.6rem;
  font-weight: 900;
  color: #fff;
  line-height: 1.1;
  text-shadow: 0 3px 12px rgba(0,0,0,0.18);
}
.app-title span { font-size: 2.8rem; }
.splash-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 280px;
}
.splash-buttons .btn {
  width: 100%;
  font-size: 1.4rem;
  padding: 20px;
}
.splash-buttons .btn-primary { background: #fff; color: var(--blue); }

/* ─── Settings ───────────────────────────────────────────── */
#screen-settings {
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.settings-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  width: 100%;
  max-width: 480px;
  padding: 32px 24px;
}
.settings-content h2 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--blue-dark);
  margin-bottom: 8px;
}
.setting-row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.setting-label {
  font-size: 1.05rem;
  font-weight: 700;
  color: #444;
  min-width: 78px;
}
select {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--tile-border);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--white);
  color: #333;
  -webkit-appearance: none;
}
.settings-content .btn-primary {
  width: 100%;
  font-size: 1.3rem;
  margin-top: 8px;
}

/* ─── Game ───────────────────────────────────────────────── */
#screen-game { background: var(--bg); }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  height: 58px;
  flex-shrink: 0;
}
.game-progress {
  font-size: 1.05rem;
  font-weight: 700;
  color: #666;
}
.game-tries {
  font-size: 1.3rem;
  letter-spacing: 2px;
  min-width: 80px;
  text-align: right;
}

/* Picture */
.picture-area {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  height: 38vh;
  min-height: 150px;
  max-height: 290px;
}
.picture-frame {
  width: 100%;
  max-width: 340px;
  height: 100%;
  background: var(--white);
  border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
#word-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 14px;
  display: none;
}
#word-image.loaded { display: block; }
.img-placeholder {
  font-size: 4.5rem;
  opacity: 0.3;
}

/* Letter Boxes */
.boxes-area {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  height: 98px;
}
.letter-box {
  width: var(--box-size);
  height: var(--box-size);
  border: 3px dashed #a8c8f0;
  border-radius: 14px;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 900;
  color: #1a1a2e;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  -webkit-user-select: none;
}
.letter-box.filled {
  border-style: solid;
  border-color: var(--blue);
  background: #eef4ff;
}
.letter-box.drag-over {
  border-color: var(--blue);
  background: #ddeeff;
  transform: scale(1.08);
}
.letter-box.correct {
  border-color: var(--green);
  background: #e5f9ee;
  color: var(--green);
}
.letter-box.wrong {
  border-color: var(--red);
  background: #fdecea;
  color: var(--red);
}

/* Feedback */
.feedback-area {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  font-size: 1.4rem;
  font-weight: 800;
}
.feedback-area.correct { color: var(--green); }
.feedback-area.wrong   { color: var(--red); }
.feedback-area.show-answer {
  color: var(--blue-dark);
  font-size: 2.2rem;
  letter-spacing: 10px;
}

/* Keyboard */
.keyboard-area {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.key-tile {
  width: var(--tile-size);
  height: var(--tile-size);
  background: var(--white);
  border: 2.5px solid var(--tile-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  font-weight: 900;
  color: #1a1a2e;
  text-transform: lowercase;
  cursor: pointer;
  box-shadow: 0 3px 7px rgba(0,0,0,0.09);
  transition: transform 0.1s, box-shadow 0.1s;
  -webkit-user-select: none;
  touch-action: none;
}
.key-tile:active,
.key-tile.selected {
  transform: scale(0.92);
  background: #e8f0fe;
  border-color: var(--blue);
  box-shadow: none;
}

/* Ghost tile */
.ghost-tile {
  position: fixed;
  width: var(--tile-size);
  height: var(--tile-size);
  background: var(--blue);
  color: #fff;
  border-radius: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  font-weight: 900;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.92;
  box-shadow: 0 8px 22px rgba(0,0,0,0.28);
  transform: scale(1.12);
}

/* ─── End Screen ─────────────────────────────────────────── */
#screen-end {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #27ae60 0%, #58d68d 100%);
}
.end-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
  color: #fff;
  padding: 24px;
}
.end-star {
  font-size: 5.5rem;
  animation: pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes pop {
  0%   { transform: scale(0); }
  100% { transform: scale(1); }
}
.end-content h2  { font-size: 3.2rem; font-weight: 900; }
.end-content p   { font-size: 1.3rem; opacity: 0.92; }
.end-content .btn { min-width: 230px; font-size: 1.2rem; }
.end-content .btn-primary { background: #fff; color: var(--green); }

/* ─── Responsive ─────────────────────────────────────────── */
@media (min-width: 768px) {
  :root { --tile-size: 70px; --box-size: 80px; }
  .app-title { font-size: 4.5rem; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .picture-area { max-height: 170px; }
  :root { --tile-size: 54px; --box-size: 62px; }
  .letter-box { font-size: 1.7rem; }
  .key-tile   { font-size: 1.5rem; }
}
