/*
 * Daily Muse — quiet interface refinements.
 * Loaded after the game and seasonal styles so every surface continues to
 * inherit the active palette from the existing brand tokens.
 */

:root {
  --ui-surface: color-mix(in srgb, var(--color-cream) 90%, var(--color-teal) 10%);
  --ui-surface-raised: color-mix(in srgb, var(--color-cream) 96%, var(--color-teal) 4%);
  --ui-line: color-mix(in srgb, var(--color-border) 76%, var(--color-ink) 24%);
  --ui-subtle: color-mix(in srgb, var(--color-muted) 86%, var(--color-cream) 14%);
  --ui-focus: color-mix(in srgb, var(--color-teal) 82%, var(--color-ink) 18%);
  --ui-entry-muted: color-mix(in srgb, var(--color-muted) 60%, var(--color-ink) 40%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The choose view is an entry screen, not a second keyboard state. */
#keyboard { display: none; }
button.hidden { display: none !important; }
body:has(#state-play:not(.hidden)) #keyboard { display: flex; }

#state-choose,
#state-results {
  overscroll-behavior-y: contain;
  scrollbar-color: var(--ui-line) transparent;
  scrollbar-width: thin;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

#state-choose {
  gap: 15px;
  scroll-padding-block: 16px;
}

#name-field,
#prize-email-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#name-field label,
#prize-email-field label {
  line-height: 1.25;
}

#name-input,
#prize-email-input {
  background: var(--ui-surface-raised);
  color: var(--color-ink);
}

#name-input:focus-visible,
#prize-email-input:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
}

#email-help {
  display: block;
  color: var(--ui-subtle);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.88rem;
  font-style: normal;
  line-height: 1.35;
  letter-spacing: normal;
  text-transform: none;
}

.difficulty-row {
  gap: 10px;
}

.diff-btn {
  min-width: 0;
  opacity: 1;
  pointer-events: auto;
  background: var(--ui-surface-raised);
}

.diff-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.diff-btn.enabled { pointer-events: auto; }
.diff-btn .btn-label { color: var(--color-ink); }
.diff-btn .btn-sub { color: var(--ui-entry-muted); }

#state-choose .game-hint { color: var(--ui-entry-muted); }

/* Approved decorative Muse tiles; deliberately separate from puzzle tiles. */
#state-choose .entry-muse-tiles {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  height: 89px;
  margin: -2px 0 -1px;
  isolation: isolate;
}

#state-choose .entry-muse-tile {
  position: absolute;
  display: grid;
  place-items: center;
  width: 49px;
  height: 49px;
  border: 1px solid rgba(108, 78, 46, .15);
  border-radius: 9px;
  background: #176d69;
  color: #fff9e8;
  box-shadow: 0 4px 0 #0f5552, 0 8px 13px rgba(70, 73, 49, .13);
  font-family: 'Cinzel', serif;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
}

#state-choose .entry-muse-tile:nth-child(1) {
  margin-left: -165px;
  background: #bf7441;
  box-shadow: 0 4px 0 #96552d, 0 8px 13px rgba(70, 73, 49, .13);
  transform: rotate(-13deg) translateY(2px);
}

#state-choose .entry-muse-tile:nth-child(2) {
  margin-left: -82px;
  transform: rotate(7deg) translateY(-8px);
}

#state-choose .entry-muse-tile:nth-child(3) {
  background: #dbad6d;
  color: #365750;
  box-shadow: 0 4px 0 #b48a52, 0 8px 13px rgba(70, 73, 49, .13);
  transform: rotate(-5deg);
}

#state-choose .entry-muse-tile:nth-child(4) {
  margin-left: 82px;
  transform: rotate(10deg) translateY(-7px);
}

#state-choose .entry-muse-tile:nth-child(5) {
  margin-left: 165px;
  background: #d18e70;
  box-shadow: 0 4px 0 #ae6d51, 0 8px 13px rgba(70, 73, 49, .13);
  transform: rotate(-9deg) translateY(2px);
}

@media (max-width: 380px) {
  #state-choose .entry-muse-tiles { height: 79px; }
  #state-choose .entry-muse-tile { width: 43px; height: 43px; font-size: 1.15rem; }
  #state-choose .entry-muse-tile:nth-child(1) { margin-left: -144px; }
  #state-choose .entry-muse-tile:nth-child(2) { margin-left: -72px; }
  #state-choose .entry-muse-tile:nth-child(4) { margin-left: 72px; }
  #state-choose .entry-muse-tile:nth-child(5) { margin-left: 144px; }
}

.diff-btn:hover,
.diff-btn.enabled:hover {
  background: var(--ui-surface);
}

.diff-btn.selected,
.diff-btn[aria-pressed="true"],
.diff-btn.selected:hover,
.diff-btn[aria-pressed="true"]:hover {
  border-color: var(--ui-focus);
  background: color-mix(in srgb, var(--color-cream) 58%, var(--color-teal) 42%);
  box-shadow: inset 0 0 0 1px var(--ui-focus);
  opacity: 1;
}

.diff-btn.selected .btn-label,
.diff-btn[aria-pressed="true"] .btn-label,
.diff-btn.selected .btn-sub,
.diff-btn[aria-pressed="true"] .btn-sub {
  color: var(--color-ink);
}

#start-game-btn {
  width: 100%;
  min-height: 48px;
  margin-top: 1px;
  box-shadow: 0 2px 0 color-mix(in srgb, var(--color-ink) 20%, transparent);
}

#start-game-btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

#leaderboard-link {
  padding: 5px 8px;
  text-underline-offset: 3px;
}

#game-options {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  padding: 10px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 7px;
  background: var(--ui-surface);
  color: var(--color-ink);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.94rem;
  line-height: 1.3;
}

#game-options label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  cursor: pointer;
}

#game-options input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-teal);
}

#scoring-guide {
  width: 100%;
  border-top: 1px solid var(--ui-line);
  border-bottom: 1px solid var(--ui-line);
  color: var(--color-ink);
}

#scoring-guide summary {
  padding: 10px 2px;
  color: var(--color-teal);
  cursor: pointer;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#scoring-guide > :not(summary) {
  margin: 0 2px 12px;
}

#elapsed-time {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 10px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface);
  color: var(--color-muted);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

body:has(#show-timer:checked) #elapsed-time { display: inline-flex; }

#grid .grid-row.active-row {
  outline: 2px solid color-mix(in srgb, var(--color-teal) 78%, transparent);
  outline-offset: 3px;
  border-radius: 5px;
}

html.tile-cues .tile[data-cue]::after {
  position: absolute;
  top: 1px;
  right: 3px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  color: currentColor;
  opacity: 0.9;
  pointer-events: none;
}

html.tile-cues .tile[data-cue="correct"]::after { content: "✓"; }
html.tile-cues .tile[data-cue="misplaced"]::after,
html.tile-cues .tile[data-cue="wrong-pos"]::after { content: "↔"; }
html.tile-cues .tile[data-cue="absent"]::after { content: "×"; }

#score-summary {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-line);
}

#score-summary > * {
  min-width: 0;
  padding: 9px 12px;
  background: var(--ui-surface);
}

#score-summary .metric-label,
#score-summary .metric-value { display: block; }

#email-requirement {
  font-family: 'Cormorant Garamond', serif;
  font-size: .82rem;
  font-weight: normal;
  letter-spacing: normal;
  text-transform: none;
  color: var(--color-muted);
}

#score-summary dt,
#score-summary .metric-label {
  color: var(--ui-subtle);
  font-family: 'Cinzel', serif;
  font-size: 0.62rem;
  letter-spacing: 0.07em;
  line-height: 1.3;
  text-transform: uppercase;
}

#score-summary dd,
#score-summary .metric-value {
  margin: 3px 0 0;
  color: var(--color-ink);
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

#score-breakdown {
  width: 100%;
  border-block: 1px solid var(--ui-line);
}

#score-breakdown summary {
  padding: 9px 2px;
  color: var(--color-teal);
  cursor: pointer;
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#score-breakdown dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 14px;
  padding: 0 3px 12px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.94rem;
  line-height: 1.3;
}

#score-breakdown dt { color: var(--color-muted); }
#score-breakdown dd {
  margin: 0;
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#prize-save-status {
  margin-top: 8px;
  color: var(--color-muted);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.9rem;
  line-height: 1.35;
}

#prize-save-status:is([data-state="saving"], [data-status="saving"], .saving) {
  color: var(--color-muted);
}
#prize-save-status:is([data-state="error"], [data-status="error"], .error) {
  color: var(--color-dark-text);
}
#prize-save-status:is([data-state="confirmed"], [data-status="confirmed"], .confirmed) {
  color: var(--color-teal);
}

#prize-retry-btn,
#lb-refresh-btn,
#lb-modal-retry {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--color-teal);
  border-radius: 5px;
  background: var(--ui-surface-raised);
  color: var(--color-teal);
  cursor: pointer;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.9rem;
}

#prize-retry-btn:hover,
#lb-refresh-btn:hover,
#lb-modal-retry:hover {
  background: var(--ui-surface);
}

#leaderboard-section {
  min-width: 0;
}

#leaderboard-table.hidden,
#lb-status.hidden { display: none !important; }

#lb-status,
#lb-modal-empty {
  margin: 0;
  padding: 18px 12px 8px;
  color: var(--color-ink);
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  line-height: 1.4;
  text-align: center;
}

#lb-refresh-btn,
#lb-modal-retry {
  display: block;
  min-height: 44px;
  margin: 0 auto;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--ui-focus);
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
  text-decoration: underline;
  text-underline-offset: 4px;
}

#lb-refresh-btn:disabled,
#lb-modal-retry:disabled {
  cursor: wait;
}

#lb-refresh-btn:focus-visible,
#lb-modal-retry:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
}

#lb-collapsible {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#leaderboard-table,
#lb-modal-table {
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

#leaderboard-table th,
#lb-modal-table th {
  color: var(--color-muted);
  white-space: nowrap;
}

#leaderboard-table th,
#leaderboard-table td,
#lb-modal-table th,
#lb-modal-table td {
  padding-inline: clamp(3px, 1.4vw, 8px);
}

#leaderboard-table td,
#lb-modal-table td {
  overflow-wrap: anywhere;
}

/* Five-column rank / name / attempts / time / score tables. */
#leaderboard-table th:nth-child(1),
#lb-modal-table th:nth-child(1) { width: 9%; }
#leaderboard-table th:nth-child(2),
#lb-modal-table th:nth-child(2) { width: 33%; }
#leaderboard-table th:nth-child(3),
#lb-modal-table th:nth-child(3) { width: 20%; }
#leaderboard-table th:nth-child(4),
#lb-modal-table th:nth-child(4) { width: 17%; }
#leaderboard-table th:nth-child(5),
#lb-modal-table th:nth-child(5) { width: 21%; }

#leaderboard-table th:nth-child(n+3),
#leaderboard-table td:nth-child(n+3),
#lb-modal-table th:nth-child(n+3),
#lb-modal-table td:nth-child(n+3) {
  text-align: right;
}

#leaderboard-table td:nth-child(2),
#lb-modal-table td:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#lb-refresh-note,
#lb-modal-note {
  color: var(--ui-subtle);
}

#lb-modal-overlay,
#htp-overlay {
  padding: max(12px, env(safe-area-inset-top)) 12px 0;
}

#lb-modal,
#htp-modal {
  background: var(--color-cream);
  color: var(--color-ink);
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}

#lb-modal {
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)));
}

#htp-modal {
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)));
}

button,
a,
summary,
input,
.mystery-box {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible,
input:focus-visible,
.mystery-box:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 3px;
}

@media (max-width: 360px) {
  #state-choose { padding-inline: 12px; }
  #game-options { gap: 6px 12px; padding-inline: 8px; }
  #leaderboard-table th,
  #leaderboard-table td,
  #lb-modal-table th,
  #lb-modal-table td {
    font-size: 0.82rem;
    padding-inline: 3px;
  }
}

@media (max-height: 620px) {
  #header { padding-top: 12px; }
  #state-choose,
  #state-results {
    padding-top: 10px;
    gap: 10px;
  }
  #brand-logo { height: clamp(54px, 14vw, 72px); }
}

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

/* Entry identity and actions: keep authentication presentation inside the
   chooser so the play, score, and results surfaces retain their own rhythm. */
#state-choose #prize-email-field {
  width: 100%;
  align-self: stretch;
  margin: 0;
  text-align: left;
}

#state-choose #prize-email-input {
  display: block;
}

#state-choose #player-identity-status {
  display: block;
  margin: 0;
  color: var(--ui-entry-muted);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.96rem;
  line-height: 1.35;
  text-align: left;
  overflow-wrap: anywhere;
}

#state-choose #entry-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
}

#state-choose #player-sign-in {
  width: 100%;
  min-height: 48px;
}

#state-choose #prize-email-field[hidden] { display: none; }

#entry-feedback.hidden,
#game-notice.hidden { display: none; }

#entry-feedback {
  margin: 0;
  color: var(--color-ink);
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  line-height: 1.35;
}

#game-notice {
  position: fixed;
  z-index: 1000;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100% - 32px));
  padding: 12px 16px;
  border: 1px solid var(--ui-focus);
  border-radius: 6px;
  background: var(--color-cream);
  color: var(--color-ink);
  font-family: 'Cormorant Garamond', serif;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 4px 20px rgb(0 0 0 / 12%);
}

#state-choose[data-identity-state="verified"] #start-game-btn {
  order: 1;
}

#state-choose[data-identity-state="verified"] #player-sign-in {
  order: 2;
  align-self: center;
  width: auto;
  min-height: 36px;
  padding: 5px 12px;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ui-entry-muted);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.94rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
}

#state-choose[data-identity-state="verified"] #player-sign-in:hover {
  background: transparent;
  color: var(--color-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Native disclosure keeps optional settings closed until requested and
   follows the restrained rule-and-type treatment of the scoring guide. */
#state-choose #game-options {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-top: 1px solid var(--ui-line);
  border-bottom: 1px solid var(--ui-line);
  border-radius: 0;
  background: transparent;
  color: var(--color-ink);
  font-size: 0.94rem;
  line-height: 1.3;
}

#state-choose #game-options summary {
  padding: 10px 2px;
  color: var(--color-teal);
  cursor: pointer;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#state-choose #game-options summary::marker {
  color: var(--color-gold);
}

#state-choose #game-options .game-options-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  padding: 0 2px 12px;
}

#state-choose #game-options label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  cursor: pointer;
}

#state-choose #game-options input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-teal);
}

@media (max-width: 360px) {
  #state-choose #game-options .game-options-controls {
    gap: 4px 12px;
  }
}
