/* WordroW Game Styles */

body {
  background-image:
    radial-gradient(circle at 12% 7%, hsla(145, 55%, 56%, 0.16) 0 7.5em, transparent 7.6em),
    radial-gradient(circle at 88% 72%, hsla(29, 100%, 62%, 0.13) 0 8.5em, transparent 8.6em),
    linear-gradient(135deg, hsl(207, 100%, 97%) 0%, hsl(213, 100%, 94%) 56%, hsl(216, 100%, 83%) 100%);
  background-attachment: fixed;
}

body.green,
body.red {
  background-image: none;
}

body:not(.cordova-app)::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 12%, hsla(210, 100%, 96%, 0.72), transparent 15em),
    radial-gradient(circle at 50% 64%, hsla(255, 100%, 100%, 0.38), transparent 16em);
  pointer-events: none;
  z-index: -1;
}

/* Game header & logo */
.game-header {
  display: flex;
  justify-content: center;
  padding: 0.5em 0;
  position: relative;
  z-index: 5;
}

.logo-link {
  display: inline-block;
  text-decoration: none;
  transition: transform 0.3s, opacity 0.3s;
  width: var(--game-row-width, min(20em, calc(100vw - 2.5em)));
}

.logo-link:hover {
  opacity: 0.85;
}

.game-logo {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  transition: width 0.3s, height 0.3s;
}

.game-logo.small {
  width: 100%;
  height: auto;
}

.cordova-app .theme-toggle {
  display: none;
}

.cordova-app .game-header {
  padding-top: 1em;
}

/* Layout sections */
.game-section {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.section-heading {
  text-align: center;
  margin: 0.5em 0;
  color: var(--color-text);
}

/* Start section */
.start-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5em;
  padding: 1.5em 0;
}

/* Buttons */
.btn {
  all: unset;
  cursor: pointer;
  color: var(--color-text);
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.92), hsla(215, 100%, 88%, 0.74)),
    var(--color-surface-alt);
  border: 1px solid hsla(218, 30%, 15%, 0.18);
  font-weight: bold;
  padding: 0.8em 1.5em;
  text-transform: uppercase;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 10px var(--color-shadow);
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.95);
}

.btn:hover {
  background: var(--color-border);
  color: var(--color-surface);
}

.btn:disabled {
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.55), hsla(215, 100%, 90%, 0.38)),
    var(--color-surface);
  color: var(--color-text-muted);
  transform: scale(1);
  cursor: default;
}

.btn-play {
  background: var(--color-accent);
  color: black;
  font-size: 1.4em;
  padding: 0.8em 3em;
  border-radius: var(--radius-lg);
  letter-spacing: 0.05em;
}

.btn-play:hover {
  background: var(--color-accent-hover);
  color: var(--color-text);
}

.btn-secondary {
  background: hsla(210, 100%, 97%, 0.44);
  border-color: hsla(218, 30%, 15%, 0.18);
  font-size: 0.9em;
}

.btn-secondary:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

/* Practice modes — small, subtle */
.practice-modes {
  display: flex;
  gap: 0.75em;
  justify-content: center;
}

.btn-practice {
  all: unset;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--color-text-muted);
  padding: 0.5em 1.2em;
  border: 1px solid transparent;
  border-radius: var(--radius);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: color 0.2s, border-color 0.2s;
}

.btn-practice:hover {
  color: var(--color-text);
  border-color: var(--color-border);
}

.link-button {
  text-decoration: none;
  color: var(--color-text);
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.92), hsla(215, 100%, 88%, 0.74)),
    var(--color-surface-alt);
  border: 1px solid hsla(218, 30%, 15%, 0.18);
  font-weight: bold;
  padding: 0.8em 1.5em;
  text-transform: uppercase;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 10px var(--color-shadow);
  display: inline-block;
  transition: transform 0.15s;
}

.link-button:hover {
  background: var(--color-border);
  color: var(--color-surface);
}

/* Tiles */
.tile {
  all: unset;
  cursor: pointer;
  background: var(--tile-bg);
  border: var(--tile-border) solid 1px;
  width: 1em;
  height: 1em;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.25em;
  font-size: 1.5em;
  padding: 0.5em;
  text-transform: uppercase;
  box-shadow: 0 4px 10px var(--tile-shadow);
  font-weight: bold;
  font-family: var(--font-family);
}

.tile.choose {
  background-color: var(--tile-choose-bg);
  border-color: var(--tile-choose-border);
}

.tile.error {
  background-color: var(--tile-error-bg);
  border-color: var(--tile-error-border);
  text-decoration: line-through;
}

.tile.good {
  background-color: var(--tile-good-bg);
  border-color: var(--tile-good-border);
}

/* Stack */
#stack-section {
  display: flex;
  flex-direction: column;
  margin-bottom: 1em;
  transition: transform 1s;
  position: relative;
  z-index: 1;
}

#stack-section.stackdown {
  animation: stackdown 0.25s forwards;
}

#stack-section.stackup {
  animation: stackup 0.25s forwards;
}

.attempt-row {
  display: flex;
  flex-direction: row;
  justify-content: center;
  opacity: 1;
}

#stack-section.stackdown .attempt-row.fade-out {
  animation: rowfade 0.25s forwards;
}

@keyframes rowfade {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes stackdown {
  0%   { transform: translateY(0); }
  100% { transform: translateY(14%); }
}

@keyframes stackup {
  0%   { transform: translateY(0); }
  100% { transform: translateY(-14%); }
}

/* Hint row */
#hint-section {
  display: flex;
  flex-direction: row;
  justify-content: center;
  position: relative;
  z-index: 2;
}

/* Timer bar */
#timer-bar {
  width: var(--game-row-width, min(20em, calc(100vw - 2.5em)));
  height: 6px;
  background: linear-gradient(90deg, var(--color-accent), var(--color-error));
  border-radius: 3px;
  transform: scaleX(var(--timer-progress, 1));
  transform-origin: left center;
  transition: transform 1s linear;
  margin: 0.75em auto;
}

/* Banner */
#banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
}

#banner.show {
  opacity: 1;
  animation: slideup 0.5s forwards;
}

@keyframes slideup {
  0%   { opacity: 1; transform: translate(-50%, 300%); }
  100% { opacity: 0; transform: translate(-50%, -10vh) scale(3); }
}

/* Score dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: hsla(0, 0%, 0%, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.dialog {
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.96), hsla(215, 100%, 90%, 0.9)),
    var(--color-surface);
  color: var(--color-text);
  width: min(85vw, 440px);
  padding: 1.5em;
  border-radius: var(--radius-lg);
  border: 1px solid hsla(218, 30%, 15%, 0.14);
  box-shadow: 0 18px 42px hsla(218, 65%, 42%, 0.22);
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

.dialog header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog header h2 {
  margin: 0;
}

.dialog-close {
  all: unset;
  cursor: pointer;
  font-size: 1.5em;
  padding: 0.25em;
}

.dialog hr {
  border: none;
  height: 1px;
  background: var(--color-border);
}

.dialog nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(8.5em, 10em));
  justify-content: center;
  gap: 0.75em;
  margin-top: 0.5em;
}

.dialog nav .btn,
.dialog nav .link-button {
  white-space: nowrap;
}

#dialog-share-btn {
  min-width: 0;
}

.cordova-app .dialog {
  width: min(86vw, 360px);
  padding: 1.25em;
}

.cordova-app .dialog nav {
  grid-template-columns: repeat(2, minmax(8.5em, 10em));
}

.cordova-app .dialog nav .btn,
.cordova-app .dialog nav .link-button {
  width: 100%;
  min-width: 0;
  padding: 0.7em 0.5em;
  font-size: 0.9em;
  line-height: 1.1;
  text-align: center;
}

.cordova-app #dialog-share-btn {
  min-width: 0;
}

.new-high {
  color: var(--color-accent);
}

.legend-text {
  font-size: 0.85em;
  color: var(--color-text-muted);
}

/* Tips */
#tips {
  text-align: center;
  font-size: 0.9em;
  color: var(--color-text-muted);
  min-height: 1.5em;
}

/* High scores */
.high-scores-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0.5em 0;
}

.high-scores-table {
  font-size: 1.3em;
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.92), hsla(215, 100%, 88%, 0.76)),
    var(--color-surface);
  box-shadow: 0 10px 28px hsla(218, 65%, 42%, 0.14);
  border-radius: var(--radius-lg);
  padding: 0.75em 1em;
  border: 1px solid hsla(218, 30%, 15%, 0.14);
  border-collapse: collapse;
  width: 100%;
}

.high-scores-table th {
  text-transform: capitalize;
  font-weight: normal;
  color: var(--color-text-muted);
  padding: 0.3em 0.5em;
}

.high-scores-table td {
  text-align: center;
  font-weight: normal;
  padding: 0.3em 0.5em;
}

/* Leaderboard */
.leaderboard-section {
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.92), hsla(215, 100%, 88%, 0.76)),
    var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1em;
  margin-bottom: 1em;
  border: 1px solid hsla(218, 30%, 15%, 0.14);
  box-shadow: 0 10px 28px hsla(218, 65%, 42%, 0.14);
}

.leaderboard-title {
  text-align: center;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, hsl(210, 100%, 96%), hsl(213, 100%, 92%));
  padding: 0.5em 0;
}

.leaderboard-empty {
  text-align: center;
  color: var(--color-text-muted);
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 2.8em minmax(0, 1fr) 3em 3em 4.1em;
  gap: 0.25em;
  padding: 0.25em 0;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

.leaderboard-row span {
  background: var(--tile-bg);
  border: var(--tile-border) solid 1px;
  border-radius: var(--radius);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 3em;
  min-width: 0;
  padding: 0.35em 0.25em;
  text-align: center;
  font-weight: bold;
  line-height: 1;
  text-transform: uppercase;
}

.leaderboard-row-1 span {
  background: linear-gradient(180deg, hsl(48, 100%, 88%), hsl(43, 100%, 62%));
  border-color: hsl(38, 100%, 38%);
  box-shadow: 0 4px 12px hsla(43, 100%, 45%, 0.26);
  color: hsl(218, 30%, 15%);
}

.leaderboard-row-2 span {
  background: linear-gradient(180deg, hsl(220, 18%, 96%), hsl(218, 14%, 74%));
  border-color: hsl(218, 10%, 48%);
  box-shadow: 0 4px 12px hsla(218, 20%, 50%, 0.22);
  color: hsl(218, 30%, 15%);
}

.leaderboard-row-3 span {
  background: linear-gradient(180deg, hsl(29, 100%, 84%), hsl(25, 76%, 50%));
  border-color: hsl(23, 74%, 34%);
  box-shadow: 0 4px 12px hsla(25, 76%, 42%, 0.24);
  color: hsl(218, 30%, 15%);
}

.leaderboard-row-1 .lb-rank,
.leaderboard-row-2 .lb-rank,
.leaderboard-row-3 .lb-rank {
  font-size: 1.28em;
}

.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-blue { background-color: var(--lb-blue-bg); border-color: var(--lb-blue-border); }
.lb-green { background-color: var(--lb-green-bg); border-color: var(--lb-green-border); }
.lb-red { background-color: var(--lb-red-bg); border-color: var(--lb-red-border); }
.lb-gray { background-color: var(--lb-gray-bg); border-color: var(--lb-gray-border); }
.lb-yellow { background-color: var(--lb-yellow-bg); border-color: var(--lb-yellow-border); }

/* Dictionary selector */
.dict-section {
  display: flex;
  justify-content: center;
  padding: 0.5em 0;
}

.dict-fieldset {
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.84), hsla(215, 100%, 88%, 0.62)),
    var(--color-surface);
  border: 1px solid hsla(218, 30%, 15%, 0.16);
  border-radius: var(--radius-lg);
  padding: 0.75em 1.5em;
  display: flex;
  flex-direction: row;
  gap: 1em;
  align-items: center;
  min-inline-size: 0;
}

.dict-fieldset legend {
  color: var(--color-text-muted);
  font-size: 0.9em;
  display: contents;
  float: none;
  margin-right: 0;
  padding: 0;
}

.dict-fieldset label {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  cursor: pointer;
}

/* App store section (in-game) */
.app-links-game {
  text-align: center;
  margin: 1.5em 0;
  font-size: 0.9em;
  color: var(--color-text-muted);
}

.store-badges-row {
  display: flex;
  justify-content: center;
  gap: 0.75em;
  margin-top: 0.5em;
}

.store-badges-row a {
  display: inline-block;
}

/* How to play */
.how-to-play-section {
  padding: 0.5em 0;
}

.how-to-play-section details {
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.92), hsla(215, 100%, 88%, 0.76)),
    var(--color-surface);
  border: 1px solid hsla(218, 30%, 15%, 0.14);
  border-radius: var(--radius-lg);
  padding: 1em 1.5em;
  box-shadow: 0 10px 28px hsla(218, 65%, 42%, 0.14);
}

.how-to-play-section summary {
  cursor: pointer;
  font-weight: bold;
  font-size: 1.1em;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.how-to-play-section summary::before {
  content: '?';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  background: var(--color-accent);
  color: black;
  font-size: 0.85em;
  flex-shrink: 0;
}

.how-to-play-section summary::-webkit-details-marker {
  display: none;
}

.how-to-play-section p {
  font-weight: normal;
  margin: 0.75em 0 0;
  line-height: 1.5;
  color: var(--color-text-muted);
}

/* Footer */
footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2em 1em;
  font-size: 0.75em;
  color: var(--color-text-muted);
  text-align: center;
  gap: 0.5em;
}

footer a {
  color: var(--color-text-muted);
}

.cordova-app footer {
  width: 100%;
  padding: 0.85em 0.5em calc(0.85em + env(safe-area-inset-bottom));
  font-size: 0.75em;
  line-height: 1.25;
}

.cordova-app footer p {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Leaderboard form */
.save-score-form {
  background:
    linear-gradient(180deg, hsla(210, 100%, 97%, 0.94), hsla(215, 100%, 88%, 0.8)),
    var(--color-surface);
  padding: 1.5em;
  border-radius: var(--radius-lg);
  border: 1px solid hsla(218, 30%, 15%, 0.14);
  display: flex;
  flex-direction: column;
  gap: 0.75em;
  align-items: center;
  box-shadow: 0 10px 28px hsla(218, 65%, 42%, 0.14);
  margin-bottom: 1em;
}

.save-score-form .form-row {
  display: flex;
  gap: 0.5em;
  align-items: baseline;
}

.save-score-form input {
  font-size: 1.2em;
  padding: 0.4em 0.5em;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-alt);
  color: var(--color-text);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body {
    background-image:
      radial-gradient(circle at 12% 7%, hsla(145, 55%, 40%, 0.12) 0 7.5em, transparent 7.6em),
      radial-gradient(circle at 88% 72%, hsla(29, 100%, 55%, 0.1) 0 8.5em, transparent 8.6em),
      linear-gradient(135deg, hsl(225, 25%, 10%) 0%, hsl(222, 31%, 13%) 56%, hsl(216, 32%, 20%) 100%);
  }

  :root:not([data-theme="light"]) .btn,
  :root:not([data-theme="light"]) .link-button,
  :root:not([data-theme="light"]) .high-scores-table,
  :root:not([data-theme="light"]) .leaderboard-section,
  :root:not([data-theme="light"]) .dict-fieldset,
  :root:not([data-theme="light"]) .how-to-play-section details,
  :root:not([data-theme="light"]) .save-score-form {
    background:
      linear-gradient(180deg, hsla(215, 34%, 24%, 0.9), hsla(216, 36%, 18%, 0.78)),
      var(--color-surface);
    border-color: hsla(220, 20%, 92%, 0.12);
    box-shadow: 0 10px 28px hsla(225, 50%, 5%, 0.36);
  }

  :root:not([data-theme="light"]) .dialog {
    background:
      linear-gradient(180deg, hsla(215, 34%, 24%, 0.96), hsla(216, 36%, 18%, 0.92)),
      var(--color-surface);
    border-color: hsla(220, 20%, 92%, 0.12);
    box-shadow: 0 18px 42px hsla(225, 50%, 5%, 0.48);
  }

  :root:not([data-theme="light"]) .leaderboard-title {
    background: linear-gradient(180deg, hsl(215, 34%, 24%), hsl(216, 36%, 18%));
  }

  :root:not([data-theme="light"]) .btn-secondary {
    background: hsla(215, 34%, 24%, 0.42);
  }

  :root:not([data-theme="light"]) body:not(.cordova-app)::before {
    display: none;
  }

  :root:not([data-theme="light"]) .leaderboard-row-1 span {
    background: linear-gradient(180deg, hsl(45, 78%, 42%), hsl(38, 70%, 28%));
    border-color: hsl(43, 100%, 62%);
    color: hsl(48, 100%, 94%);
  }

  :root:not([data-theme="light"]) .leaderboard-row-2 span {
    background: linear-gradient(180deg, hsl(218, 16%, 42%), hsl(218, 18%, 28%));
    border-color: hsl(220, 18%, 76%);
    color: hsl(220, 20%, 96%);
  }

  :root:not([data-theme="light"]) .leaderboard-row-3 span {
    background: linear-gradient(180deg, hsl(26, 68%, 38%), hsl(22, 66%, 25%));
    border-color: hsl(29, 100%, 68%);
    color: hsl(29, 100%, 94%);
  }
}

:root[data-theme="dark"] body {
  background-image:
    radial-gradient(circle at 12% 7%, hsla(145, 55%, 40%, 0.12) 0 7.5em, transparent 7.6em),
    radial-gradient(circle at 88% 72%, hsla(29, 100%, 55%, 0.1) 0 8.5em, transparent 8.6em),
    linear-gradient(135deg, hsl(225, 25%, 10%) 0%, hsl(222, 31%, 13%) 56%, hsl(216, 32%, 20%) 100%);
}

:root[data-theme="dark"] .btn,
:root[data-theme="dark"] .link-button,
:root[data-theme="dark"] .high-scores-table,
:root[data-theme="dark"] .leaderboard-section,
:root[data-theme="dark"] .dict-fieldset,
:root[data-theme="dark"] .how-to-play-section details,
:root[data-theme="dark"] .save-score-form {
  background:
    linear-gradient(180deg, hsla(215, 34%, 24%, 0.9), hsla(216, 36%, 18%, 0.78)),
    var(--color-surface);
  border-color: hsla(220, 20%, 92%, 0.12);
  box-shadow: 0 10px 28px hsla(225, 50%, 5%, 0.36);
}

:root[data-theme="dark"] .dialog {
  background:
    linear-gradient(180deg, hsla(215, 34%, 24%, 0.96), hsla(216, 36%, 18%, 0.92)),
    var(--color-surface);
  border-color: hsla(220, 20%, 92%, 0.12);
  box-shadow: 0 18px 42px hsla(225, 50%, 5%, 0.48);
}

:root[data-theme="dark"] .leaderboard-title {
  background: linear-gradient(180deg, hsl(215, 34%, 24%), hsl(216, 36%, 18%));
}

:root[data-theme="dark"] .btn-secondary {
  background: hsla(215, 34%, 24%, 0.42);
}

:root[data-theme="dark"] body:not(.cordova-app)::before {
  display: none;
}

:root[data-theme="dark"] .leaderboard-row-1 span {
  background: linear-gradient(180deg, hsl(45, 78%, 42%), hsl(38, 70%, 28%));
  border-color: hsl(43, 100%, 62%);
  color: hsl(48, 100%, 94%);
}

:root[data-theme="dark"] .leaderboard-row-2 span {
  background: linear-gradient(180deg, hsl(218, 16%, 42%), hsl(218, 18%, 28%));
  border-color: hsl(220, 18%, 76%);
  color: hsl(220, 20%, 96%);
}

:root[data-theme="dark"] .leaderboard-row-3 span {
  background: linear-gradient(180deg, hsl(26, 68%, 38%), hsl(22, 66%, 25%));
  border-color: hsl(29, 100%, 68%);
  color: hsl(29, 100%, 94%);
}

body.green,
body.red,
:root[data-theme="dark"] body.green,
:root[data-theme="dark"] body.red {
  background-image: none;
}

/* Rotate animation for trophies */
.rotate {
  display: inline-block;
  animation: rotator 3s linear infinite;
}

@keyframes rotator {
  0%   { transform: rotateY(0deg); }
  100% { transform: rotateY(360deg); }
}
