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

:root {
  --bg:          #0d0d1a;
  --surface:     #13132b;
  --surface2:    #1a1a38;
  --cell-empty:  #1e1e40;
  --cell-border: #2a2a55;
  --accent:      #7c3aed;
  --accent2:     #ec4899;
  --gold:        #fbbf24;
  --green:       #34d399;
  --red:         #f87171;
  --text:        #e8e8f5;
  --text-dim:    #8888b0;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.5);
}

html { height: 100%; background: var(--bg); }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

button { font: inherit; }

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: min(100dvh, 900px);
  max-width: 480px;
  padding: env(safe-area-inset-top, 8px) 12px env(safe-area-inset-bottom, 8px);
  gap: 8px;
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 4px 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.28rem;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  flex: 1;
}

.logo-back {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.45);
  text-decoration: none;
  -webkit-text-fill-color: rgba(255,255,255,0.45);
  transition: color 0.15s;
}
.logo-back:hover { -webkit-text-fill-color: rgba(255,255,255,0.85); }

.header-player {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255,255,255,0.38);
  -webkit-text-fill-color: rgba(255,255,255,0.38);
  letter-spacing: 0.01em;
}

.scores { display: flex; gap: 10px; }
.score-box { text-align: center; line-height: 1.1; }

.score-box .label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  display: block;
}

.score-box .value {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.header-btns { display: flex; gap: 6px; }

.icon-btn {
  background: var(--surface2);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { transform: scale(0.9); background: var(--surface); }

.meter-section {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

#meter-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  min-width: 48px;
}

#meter-count {
  min-width: 34px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.meter-track {
  flex: 1;
  height: 8px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}

#meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

#meter-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.28), transparent);
  animation: shimmer 2s infinite;
}

.meter-stars {
  font-size: 0.85rem;
  min-width: 20px;
  text-align: center;
}

#app-version {
  color: rgba(245, 247, 251, 0.42);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#game-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(10px, 2.6dvh, 18px);
}

#board-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

#board {
  width: min(100%, 380px, calc(100dvh - 280px));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 6px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.05);
}

.tile {
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  background: var(--cell-empty);
  border: 1px solid var(--cell-border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
  transform-style: preserve-3d;
  transition: transform 0.1s, background 0.18s, border-color 0.18s;
}

.tile.filled:not(.revealed) {
  border-color: rgba(124,58,237,.78);
  box-shadow: inset 0 0 0 1px rgba(124,58,237,.34), 0 0 12px rgba(124,58,237,.16);
  animation: popTile 0.1s ease-out;
}

.tile.hit {
  background: #1d4e2a;
  border-color: var(--green);
  color: #fff;
}

.tile.place {
  background: #5f4309;
  border-color: var(--gold);
  color: #fff;
}

.tile.miss {
  background: #252545;
  border-color: #34345d;
  color: rgba(232,232,245,.62);
}

.tile.flip { animation: flipTile 0.42s ease both; }
.tile.shake { animation: shakeRow 0.35s ease; }

#feedback {
  position: absolute;
  top: calc(50% - 18px);
  left: 0;
  right: 0;
  font-size: 1.32rem;
  font-weight: 900;
  pointer-events: none;
  z-index: 10;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0,0,0,.82);
  opacity: 0;
  padding: 0 10px;
  overflow-wrap: anywhere;
}

#feedback.feedback-score { color: var(--gold); font-size: 1.8rem; }
#feedback.feedback-bad { color: var(--red); }
#feedback.feedback-info { color: rgba(245,247,251,.88); }
#feedback.feedback-anim { animation: feedbackFloat 1.25s cubic-bezier(0.22, 1, 0.36, 1) forwards; }

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.key {
  min-width: 0;
  height: clamp(40px, 7dvh, 54px);
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s, background .15s, color .15s;
}

.key:active { transform: scale(.94); }
.key-enter, .key-backspace { flex: 1.55; font-size: 0.78rem; }
.key.hit { background: #1d4e2a; color: #fff; }
.key.place { background: #5f4309; color: #fff; }
.key.miss { background: #252545; color: rgba(232,232,245,.52); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: all;
}

.modal-backdrop.hidden { display: none; }

.modal-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalIn 0.34s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.intro-card { max-width: 380px; }

.modal-card h2 {
  font-size: 1.75rem;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-note {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: center;
  margin-top: -8px;
}

.intro-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.intro-item {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: .9rem;
  line-height: 1.25;
}

.intro-icon {
  width: 42px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .82rem;
  font-weight: 950;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.intro-icon.green { background: #1d4e2a; box-shadow: inset 0 0 0 2px var(--green); }
.intro-icon.gold { background: #5f4309; box-shadow: inset 0 0 0 2px var(--gold); }
.intro-icon.dim { background: #252545; color: rgba(232,232,245,.66); }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-item {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}

.result-item .r-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

.result-item .r-value {
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.word-result { letter-spacing: 1px; }

.result-item.highlight .r-value {
  background: linear-gradient(135deg, var(--gold), #f97316);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.1);
}

.btn-primary:active, .btn-secondary:active { opacity: .86; transform: scale(.97); }
.btn-share { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; cursor: pointer; font-family: inherit; font-size: .82rem; font-weight: 600; color: var(--text-dim); padding: 8px 0; transition: color .15s; }
.btn-share:hover { color: var(--text); }
.btn-share svg { flex-shrink: 0; }

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(200%); }
}

@keyframes popTile {
  from { transform: scale(.9); }
  to   { transform: scale(1); }
}

@keyframes flipTile {
  0%   { transform: rotateX(0); }
  48%  { transform: rotateX(90deg); }
  52%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@keyframes shakeRow {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes feedbackFloat {
  0%   { opacity: 0; transform: translateY(10px); }
  12%  { opacity: 1; transform: translateY(0); }
  68%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-20px); }
}

@keyframes modalIn {
  from { transform: scale(0.86) translateY(18px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

@media (max-width: 420px) {
  #app { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .scores { gap: 7px; }
  .score-box .label { font-size: .55rem; }
  .score-box .value { font-size: .96rem; }
  .streak-box { display: none; }
  #board { gap: 5px; padding: 7px; }
  .logo { font-size: 1.12rem; }
  .tile { font-size: 1.55rem; }
  #keyboard { padding: 7px 5px; }
  .key-row { gap: 3px; }
  .key { font-size: .82rem; }
  .key-enter, .key-backspace { font-size: .68rem; }
}

@media (max-height: 650px) {
  #game-area { gap: 8px; }
  #board { width: min(100%, 320px, calc(100dvh - 250px)); gap: 4px; padding: 6px; }
  .tile { font-size: 1.45rem; }
  .key { height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

::-webkit-scrollbar { display: none; }
