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

html {
 height: 100%;
 height: 100dvh;
 overflow: hidden;
 touch-action: manipulation;
 touch-action: none; /* prevent pinch-zoom where supported (e.g. Android) */
}

body {
 margin: 0;
 height: 100%;
 height: 100dvh;
 overflow: hidden;
 background-color: var(--bg);
 color: var(--text);
 font-family: "Bungee", "Helvetica Neue", Arial, sans-serif;
 padding: 0;
 -webkit-user-select: none;
 user-select: none;
 -webkit-tap-highlight-color: transparent;
 touch-action: none;
}

.game-bg {
 position: fixed;
 inset: 0;
 z-index: -1;
 overflow: hidden;
 pointer-events: none;
}

.game-bg img {
 display: block;
 width: 100%;
 height: 100%;
 object-fit: cover;
 object-position: center;
}

.loading-screen {
 position: fixed;
 inset: 0;
 z-index: 9999;
 display: flex;
 align-items: center;
 justify-content: center;
 background: var(--bg);
 color: var(--text);
 font-family: inherit;
}

body.loaded .loading-screen {
 display: none;
}

body.loading .game-container {
 visibility: hidden;
 pointer-events: none;
}

body.loaded .game-container {
 visibility: visible;
 pointer-events: auto;
}

.loading-content {
 display: flex;
 flex-direction: column;
 align-items: center;
 gap: 1rem;
}

.loading-spinner {
 width: 48px;
 height: 48px;
 border: 4px solid rgba(255, 255, 255, 0.2);
 border-top-color: currentColor;
 border-radius: 50%;
 animation: loading-spin 0.8s linear infinite;
}

.loading-text {
 margin: 0;
 font-size: 1.25rem;
 font-weight: 700;
}

@keyframes loading-spin {
 to {
  transform: rotate(360deg);
 }
}

:root {
 /* Theme defaults (overridden by config.js from gameTheme.json) – glossy letter style */
 --bg: #2d2d2d;
 --text: #ffffff;
 --tile-letter-bg: #1a1a1a;
 --tile-letter-color: #ffffff;
 --tile-border: #404040;
 --tile-filled-border: #525252;
 --correct: #16a34a;
 --present: #eab308;
 --absent: #a5b2a2;
 --key-letter-bg: #1a1a1a;
 --key-letter-color: #ffffff;
 --key-hover: #3f3f46;
 --message-lose: #f87171;
 --gloss-shine: linear-gradient(145deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0.05) 40%, transparent 70%);
 --gloss-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 2px 4px rgba(0, 0, 0, 0.3);
 /* Fluid scale: smaller viewport (dvh) = smaller UI */
 --header-font: clamp(1rem, 3.2dvh, 2rem);
 --header-padding-v: clamp(0.35rem, 1.5dvh, 1rem);
 --board-padding-v: clamp(0.4rem, 2dvh, 1.5rem);
 --gap-sm: clamp(3px, 1dvh, 5px);
 --gap-md: clamp(4px, 1.2dvh, 8px);
 --tile-size: clamp(30px, 8dvh, 72px);
 --tile-font: clamp(1.15rem, 3.2dvh, 2.25rem);
 --message-font: clamp(0.75rem, 1.8dvh, 1rem);
 --message-margin: clamp(0.15rem, 0.5dvh, 0.5rem);
 --key-height: clamp(36px, 7.5dvh, 56px);
 --key-min-width: clamp(15px, 4.5dvh, 35px);
 --key-font: clamp(0.55rem, 1.6dvh, 0.95rem);
 --key-enter-width: clamp(38px, 8dvh, 60px);
 --key-enter-font: clamp(0.6rem, 1.4dvh, 0.8rem);
 --keyboard-padding: clamp(4px, 1.2dvh, 8px);
 --keyboard-gap: clamp(4px, 1dvh, 8px);
 --key-radius: clamp(8px, 1.5dvh, 14px);
 --tile-radius: clamp(8px, 1.5dvh, 14px);
}

.game-container {
 display: flex;
 flex-direction: column;
 height: 100%;
 height: 100dvh;
 max-height: 100dvh;
 width: 100%;
 max-width: 500px;
 margin: 0 auto;
 padding: 0 0.5rem;
 padding-left: max(0.5rem, env(safe-area-inset-left));
 padding-right: max(0.5rem, env(safe-area-inset-right));
 overflow: hidden;
 min-width: 0; /* allow flex children to shrink below content size */
 /* background from gameAssets applied in script.js when loaded */
 -webkit-user-select: none;
 user-select: none;
 -webkit-tap-highlight-color: transparent;
}

.header {
 position: sticky;
 top: 0;
 z-index: 2;
 flex-shrink: 0;
 min-height: 2.25em;
 background: transparent;
 text-align: center;
 padding: var(--header-padding-v) 0 calc(var(--header-padding-v) * 0.5);
 padding-top: max(var(--header-padding-v), env(safe-area-inset-top));
 border-bottom: 1px solid var(--tile-border);
 display: flex;
 align-items: center;
 justify-content: center;
}

.board-area {
 flex: 1;
 min-height: 0;
 min-width: 0;
 display: flex;
 flex-direction: column;
 align-items: center;
 justify-content: center;
 padding: var(--board-padding-v) 0;
 overflow: hidden;
}

.header h1 {
 margin: 0;
 font-size: var(--header-font);
 font-weight: 700;
 letter-spacing: 0.1em;
 color: var(--heading-color, #1e293b);
}

.board {
 width: 100%;
 max-width: 100%;
 display: flex;
 flex-direction: column;
 align-items: stretch;
 gap: var(--gap-sm);
 margin-bottom: var(--gap-md);
 flex-shrink: 0;
 min-width: 0;
}

.board-row {
 display: grid;
 grid-template-columns: repeat(5, 1fr);
 gap: var(--gap-sm);
 width: 100%;
 max-width: 100%;
 min-width: 0;
}

.tile {
 width: 100%;
 max-width: var(--tile-size);
 max-height: var(--tile-size);
 aspect-ratio: 1;
 min-width: 0;
 min-height: 0;
 border: 2px solid var(--tile-border);
 border-radius: var(--tile-radius);
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.12) 0%, transparent 50%), var(--tile-letter-bg);
 color: var(--tile-letter-color);
 font-size: var(--tile-font);
 font-weight: 700;
 display: flex;
 align-items: center;
 justify-content: center;
 text-transform: uppercase;
 overflow: hidden;
 box-shadow: var(--gloss-shadow);
 -webkit-user-select: none;
 user-select: none;
 -webkit-tap-highlight-color: transparent;
 transition:
  transform 0.1s ease,
  border-color 0.15s ease,
  background 0.3s ease,
  color 0.3s ease,
  box-shadow 0.3s ease;
 justify-self: center;
 text-shadow:
  0 0 1px rgba(0, 0, 0, 0.5),
  0 1px 1px rgba(0, 0, 0, 0.3);
}

.tile.filled {
 border-color: var(--tile-filled-border);
 animation: pop 0.1s ease;
}

.tile.correct {
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%), var(--correct);
 border-color: var(--correct);
 color: #fff;
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.2),
  0 2px 6px rgba(0, 0, 0, 0.25);
}

.tile.present {
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%), var(--present);
 border-color: var(--present);
 color: #fff;
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.2),
  0 2px 6px rgba(0, 0, 0, 0.25);
}

.tile.absent {
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.08) 0%, transparent 50%), var(--absent);
 border-color: var(--absent);
 color: #374151;
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.1),
  0 2px 4px rgba(0, 0, 0, 0.3);
}

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

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

@keyframes flip {
 0% {
  transform: scaleY(1);
 }
 50% {
  transform: scaleY(0);
 }
 100% {
  transform: scaleY(1);
 }
}

.message {
 min-height: 1.25rem;
 font-size: var(--message-font);
 text-align: center;
 font-weight: 700;
 margin-bottom: var(--message-margin);
 padding: 0 var(--gap-sm);
 overflow: hidden;
 text-overflow: ellipsis;
 max-width: 100%;
}

.message.win {
 color: var(--correct);
}

.message.lose {
 color: var(--message-lose);
}

.keyboard {
 position: sticky;
 bottom: 0;
 z-index: 2;
 flex-shrink: 0;
 min-height: 0;
 width: 100%;
 max-width: 100%;
 background: transparent;
 display: flex;
 flex-direction: column;
 align-items: center;
 gap: var(--keyboard-gap);
 padding: var(--keyboard-padding) 0;
 padding-bottom: max(var(--keyboard-padding), env(safe-area-inset-bottom));
 min-width: 0;
}

.keyboard-row {
 width: 100%;
 max-width: 100%;
 display: flex;
 justify-content: center;
 gap: var(--gap-sm);
 min-width: 0;
}

.key {
 flex: 1 1 0;
 min-width: var(--key-min-width);
 max-width: 2.5em;
 height: var(--key-height);
 padding: 0 0.25em;
 border: none;
 border-radius: var(--key-radius);
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.15) 0%, transparent 50%), var(--key-letter-bg);
 color: var(--key-letter-color);
 font-size: var(--key-font);
 font-weight: 700;
 font-family: inherit;
 text-transform: uppercase;
 cursor: pointer;
 -webkit-user-select: none;
 user-select: none;
 -webkit-tap-highlight-color: transparent;
 touch-action: manipulation;
 transition:
  background 0.2s ease,
  color 0.2s ease,
  transform 0.1s ease,
  box-shadow 0.2s ease;
 overflow: hidden;
 text-overflow: ellipsis;
 white-space: nowrap;
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.15),
  0 2px 4px rgba(0, 0, 0, 0.35);
 text-shadow:
  0 0 1px rgba(0, 0, 0, 0.5),
  0 1px 1px rgba(0, 0, 0, 0.3);
}

.key:hover:not(:disabled) {
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%), var(--key-hover);
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.2),
  0 3px 6px rgba(0, 0, 0, 0.4);
}

.key:active {
 transform: scale(0.97);
}

.key.key-enter {
 flex: 2 1 0;
 font-size: var(--key-enter-font);
 min-width: 3em;
 max-width: 6em;
 padding: 0 0.35em;
}

.key.key-backspace {
 flex: 1.4 1 0;
 font-size: var(--key-enter-font);
 min-width: 2em;
 max-width: 4em;
}

.key:disabled {
 opacity: 0.45;
 cursor: not-allowed;
}

.key.correct {
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%), var(--correct);
 color: #fff;
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.2),
  0 2px 6px rgba(0, 0, 0, 0.25);
}

.key.present {
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%), var(--present);
 color: #fff;
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.2),
  0 2px 6px rgba(0, 0, 0, 0.25);
}

.key.absent {
 background: linear-gradient(145deg, rgba(255, 255, 255, 0.06) 0%, transparent 50%), var(--absent);
 color: #374151;
 box-shadow:
  inset 0 1px 0 rgba(255, 255, 255, 0.08),
  0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Mobile: ensure sections stay in bounds and don't overlap */
@media (max-width: 480px) {
 .game-container {
  padding-left: max(0.35rem, env(safe-area-inset-left));
  padding-right: max(0.35rem, env(safe-area-inset-right));
 }
 .header {
  min-height: 2em;
 }
 .header h1 {
  font-size: clamp(0.9rem, 2.8dvh, 1.5rem);
 }
 .board {
  padding: 0 var(--gap-sm);
 }
 .key {
  min-width: 0.75em;
  padding: 0 0.15em;
  font-size: clamp(0.5rem, 1.4dvh, 0.85rem);
 }
 .key.key-enter {
  font-size: clamp(0.5rem, 1.2dvh, 0.7rem);
  min-width: 2.5em;
  max-width: 5em;
 }
 .key.key-backspace {
  font-size: clamp(0.5rem, 1.2dvh, 0.75rem);
  min-width: 1.5em;
 }
}
