* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --bg-2: #1e1b4b;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #818cf8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #0ea5e9;
  --border: #334155;
}

html, body { min-height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app {
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border-radius: 1.5rem;
  padding: 2rem;
  box-shadow: 0 25px 50px rgba(0,0,0,.5);
  position: relative;
}

.screen { display: flex; flex-direction: column; gap: 1.25rem; }
.screen[hidden] { display: none; }

h1 {
  font-size: 1.6rem;
  background: linear-gradient(90deg, var(--accent), #c084fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}
h2 { font-size: 1.3rem; text-align: center; }
h2 span { color: var(--accent); }
h3 { font-size: 1.05rem; }

.subtitle { text-align: center; color: var(--muted); font-size: .9rem; }

form { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: .4rem; }
label > span { font-size: .8rem; color: var(--muted); font-weight: 600; }

input {
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}
input:disabled { opacity: .55; cursor: not-allowed; }

.actions { display: flex; gap: .5rem; margin-top: .5rem; }

.btn-primary, .btn-secondary, .btn-warning, .btn-info {
  flex: 1;
  padding: .8rem 1rem;
  border: none;
  border-radius: .6rem;
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  transition: background .2s;
  color: white;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #475569; }
.btn-warning { background: var(--warning); color: #1e293b; }
.btn-warning:hover:not(:disabled) { background: #d97706; }
.btn-info { background: var(--info); }
.btn-info:hover:not(:disabled) { background: #0284c7; }
.btn-primary:disabled, .btn-secondary:disabled, .btn-warning:disabled, .btn-info:disabled {
  opacity: .5; cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: .6rem;
  padding: .55rem 1rem;
  font-size: .8rem;
  cursor: pointer;
  align-self: center;
  transition: all .2s;
}
.btn-ghost:hover { border-color: var(--danger); color: var(--danger); }

.btn-icon {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .5rem;
  width: 2.2rem;
  height: 2.2rem;
  cursor: pointer;
  font-size: 1rem;
  transition: all .2s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

.mode-toggle {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .75rem;
}
.switch {
  position: relative;
  display: inline-block;
  width: 2.6rem;
  height: 1.4rem;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--border);
  transition: .25s;
  border-radius: 1.4rem;
}
.slider:before {
  content: "";
  position: absolute;
  height: 1rem;
  width: 1rem;
  left: .2rem;
  bottom: .2rem;
  background-color: white;
  transition: .25s;
  border-radius: 50%;
}
.switch input:checked + .slider { background-color: var(--info); }
.switch input:checked + .slider:before { transform: translateX(1.2rem); }
.mode-label { display: flex; flex-direction: column; gap: .1rem; }
.mode-label strong { font-size: .9rem; color: var(--text); }
.mode-label small { font-size: .72rem; color: var(--muted); }

.mode-banner {
  text-align: center;
  background: rgba(14,165,233,.15);
  border: 1px solid rgba(14,165,233,.4);
  color: #7dd3fc;
  padding: .5rem .75rem;
  border-radius: .5rem;
  font-size: .8rem;
  font-weight: 600;
}

.btn-speak {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: .35rem;
  color: var(--muted);
  cursor: pointer;
  padding: .25rem .35rem;
  margin-left: .35rem;
  vertical-align: middle;
  transition: all .2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-speak svg {
  width: 1em;
  height: 1em;
  fill: currentColor;
  display: block;
}
.btn-speak:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-speak:disabled { opacity: .3; cursor: not-allowed; }
.btn-speak-lg { padding: .45rem .55rem; }
.btn-speak-lg svg { width: 1.4em; height: 1.4em; }

.error {
  padding: .7rem 1rem;
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.4);
  border-radius: .6rem;
  color: #fca5a5;
  font-size: .85rem;
  text-align: center;
}

.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.level-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .75rem;
  padding: 1rem .75rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.level-card:hover:not(.disabled) { border-color: var(--accent); transform: translateY(-2px); }
.level-card.disabled { opacity: .4; cursor: not-allowed; }
.level-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: .25rem;
  letter-spacing: .5px;
}
.level-count { font-size: .75rem; color: var(--muted); }

.game-header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.game-info { display: flex; flex-direction: column; align-items: center; }
.game-level { font-weight: 800; color: var(--accent); font-size: 1rem; }
.game-progress { font-size: .75rem; color: var(--muted); }
.game-score { background: var(--bg); padding: .4rem .7rem; border-radius: .5rem; font-weight: 700; font-size: .85rem; }

.hangman-wrap { display: flex; justify-content: center; }
.hangman-wrap svg { width: 100%; max-width: 200px; }
.part { opacity: 0; transition: opacity .3s; stroke: var(--danger); stroke-width: 5; fill: none; stroke-linecap: round; }
.part.fill { fill: var(--danger); }
.part.visible { opacity: 1; }

.clue-box { background: var(--bg); padding: 1rem; border-radius: .75rem; border-left: 4px solid var(--primary); }
.clue-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent);
  margin-bottom: .35rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
}
.clue-label-right { display: flex; align-items: center; gap: .35rem; text-transform: none; letter-spacing: 0; }
.clue-text { font-size: .95rem; line-height: 1.5; }

.badge {
  font-size: .6rem;
  padding: .15rem .45rem;
  border-radius: .25rem;
  font-weight: 700;
  background: #7c2d12;
  color: #fdba74;
}

.word { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; min-height: 2.8rem; padding: .5rem 0; }
.letter {
  width: 1.7rem;
  height: 2.4rem;
  border-bottom: 3px solid #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  transition: all .2s;
}
.letter.revealed { border-color: var(--success); color: var(--success); }
.letter.missed { border-color: var(--danger); color: var(--danger); }
.letter.hyphen { border: none; }
.space { width: .45rem; }

.keyboard { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.key {
  aspect-ratio: 1;
  border: none;
  border-radius: .4rem;
  background: var(--border);
  color: var(--text);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  text-transform: uppercase;
}
.key:hover:not(:disabled) { background: #475569; }
.key:disabled { cursor: not-allowed; opacity: .5; }
.key.correct { background: var(--success); color: var(--bg); }
.key.wrong { background: var(--danger); color: white; }

.game-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.game-actions > * { flex: 1; min-width: 0; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.overlay[hidden] { display: none; }

.overlay-card {
  background: var(--panel);
  border-radius: 1rem;
  padding: 1.75rem;
  max-width: 480px;
  width: 100%;
  border: 1px solid var(--border);
  text-align: center;
}
.overlay-card h3 { font-size: 1.15rem; margin-bottom: .5rem; }
.overlay-title-success { color: var(--success); }
.overlay-title-danger { color: var(--danger); }
.overlay-word-row { display: flex; align-items: center; justify-content: center; gap: .5rem; flex-wrap: wrap; }
.overlay-word {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--accent);
  margin: .4rem 0;
  word-break: break-word;
}
.overlay-meta { font-size: .8rem; color: var(--muted); margin-bottom: 1rem; }
.overlay-info {
  text-align: left;
  background: var(--bg);
  padding: 1rem;
  border-radius: .75rem;
  margin-bottom: 1rem;
  font-size: .85rem;
  line-height: 1.5;
}
.overlay-info p { margin: .35rem 0; }
.overlay-info b { color: var(--accent); }

.result-big { text-align: center; background: var(--bg); border-radius: .75rem; padding: 1.25rem; }
.result-score-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: .25rem;
}
.result-score { font-size: 2.5rem; font-weight: 800; color: var(--accent); }

.ranking-title { text-align: center; font-size: .95rem; color: var(--muted); margin-top: .5rem; }

.ranking-list {
  background: var(--bg);
  border-radius: .75rem;
  max-height: 280px;
  overflow-y: auto;
  padding: .5rem;
}
.ranking-empty { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }
.ranking-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .55rem .75rem;
  border-radius: .5rem;
  font-size: .9rem;
}
.ranking-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.ranking-row.me { background: rgba(99,102,241,.15); border: 1px solid rgba(99,102,241,.4); }
.ranking-rank { font-weight: 800; color: var(--accent); min-width: 2rem; }
.ranking-name { flex: 1; margin-left: .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-score { font-weight: 700; color: var(--success); }

.toast-container {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 300;
  pointer-events: none;
  max-width: 90vw;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .7rem 1.1rem;
  border-radius: .6rem;
  font-size: .85rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0,0,0,.4);
  animation: toast-in .25s ease-out;
  max-width: 420px;
  text-align: center;
}
.toast-info { border-color: var(--info); color: #7dd3fc; }
.toast-error { border-color: var(--danger); color: #fca5a5; }
.toast-success { border-color: var(--success); color: #86efac; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
}
.modal-card h3 { font-size: 1.1rem; margin-bottom: .5rem; }
.modal-card p { font-size: .9rem; color: var(--muted); margin-bottom: 1.25rem; line-height: 1.5; }
.modal-actions { display: flex; gap: .5rem; }
.modal-actions > * { flex: 1; }
/* ---------- Branding: logo + footer ---------- */
.brand-header {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  max-height: 120px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.brand-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  letter-spacing: 0.02em;
}