:root {
  --bg: #121213;
  --bg-elevated: #1c1c1e;
  --border: #3a3a3c;
  --border-soft: #565758;
  --text: #ffffff;
  --text-dim: #a7a7a7;
  --accent: #6e56cf;
  --accent-hover: #7f68db;
  --correct: #2e7d46;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --danger: #d24444;
  --radius: 10px;
  --max-width: 480px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: radial-gradient(circle at top, #1a1a1d, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
}

.topbar-right { display: flex; gap: 6px; }

.logo {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #fff, var(--accent-hover));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo span { color: var(--accent-hover); -webkit-text-fill-color: var(--accent-hover); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn:hover { background: #262629; }
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn.used { border-color: var(--accent); color: var(--accent-hover); }

.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 10px 10px;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 6 / 6.3;
  margin: 0 auto;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  user-select: none;
  transition: transform 0.1s ease;
}

.tile.filled { border-color: var(--border-soft); animation: pop 0.1s ease; }
.tile.correct { background: var(--correct); border-color: var(--correct); }
.tile.present { background: var(--present); border-color: var(--present); }
.tile.absent { background: var(--absent); border-color: var(--absent); }

.tile.flip {
  animation: flip 0.5s ease forwards;
}

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

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

.board-row.shake { animation: shake 0.4s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.board-row.win .tile {
  animation: bounce 0.5s ease;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-14px); }
  50% { transform: translateY(0); }
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 480px;
}

.keyboard-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.key {
  flex: 1;
  min-width: 0;
  height: 52px;
  max-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: #818384;
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.key:active { transform: scale(0.94); }
.key.wide { max-width: 64px; font-size: 0.7rem; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: #3a3a3c; color: #8a8a8a; }

.toast-region {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: #fff;
  color: #121213;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  animation: toast-in 0.15s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 20px;
  max-width: 400px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: modal-in 0.18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal h2 { margin-top: 0; }
.modal-sub { color: var(--text-dim); font-size: 0.9rem; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
}
.modal-close:hover { background: #2a2a2d; color: var(--text); }

.help-example { display: flex; gap: 4px; margin: 10px 0 6px; }
.help-example .tile { width: 40px; height: 40px; font-size: 1.1rem; }

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.swatch.correct { background: var(--correct); }
.swatch.present { background: var(--present); }
.swatch.absent { background: var(--absent); }

.help-footer { color: var(--text-dim); font-size: 0.85rem; margin-top: 16px; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-dim); }
.auth-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  font-size: 1rem;
}
.auth-form input:focus { outline: 2px solid var(--accent); }

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text); display: block; text-align: center; text-decoration: none; margin-bottom: 10px; }
.btn-secondary:hover { background: #262629; }

.form-error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; }
.form-hint { color: var(--text-dim); font-size: 0.8rem; }

.result-word {
  font-size: 1.6rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 8px 0 2px;
  color: var(--accent-hover);
}
.result-definition { color: var(--text-dim); margin-bottom: 16px; }
.result-hint-note { color: var(--present); font-size: 0.85rem; margin-top: -8px; margin-bottom: 12px; }

@media (max-width: 360px) {
  .tile { font-size: 1.25rem; }
  .key { height: 46px; font-size: 0.75rem; }
}
