:root {
  --desktop: #6699cc;
  --chrome: #ece9d8;
  --chrome-dark: #b8b5a8;
  --title-start: #0a246a;
  --title-end: #3a6ea5;
  --ink: #000000;
  --ink-muted: #454545;
  --link: #0000cc;
  --online: #2a8a2a;
  --offline: #999999;
  --shadow: 2px 2px 6px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--desktop) url("assets/ui/desktop-bliss.jpg") center center / cover no-repeat fixed;
  color: var(--ink);
  font-family: Tahoma, Verdana, Arial, sans-serif;
  font-size: 15px;
}

body {
  padding: 0;
}

button, select { font: inherit; }

/* Stop iOS Safari's double-tap-to-zoom on tappable controls: quick taps flip
   cards / slide tiles instead of zooming the page (and it kills the ~300ms tap
   delay so play feels snappier). Panning and pinch-to-zoom still work, so this
   doesn't hurt accessibility — unlike a user-scalable=no viewport hack. */
button,
a,
.card,
.puzzle-tile,
.museum-cell,
.museum-nav-btn,
.museum-chip,
.picker-grid-item {
  touch-action: manipulation;
}

.page {
  width: min(880px, 100%);
  margin: 0 auto;
  padding: 18px 12px 28px;
}

.brand-banner {
  width: 100%;
  display: flex;
  justify-content: center;
  background: url("assets/ui/logo-strip.png") repeat-x center center;
  background-size: auto 100%;
}

.site-header {
  text-align: center;
  margin: 0 0 6px;
}

/* The logo link is a full-width flex item that centers the image. Earlier this
   used display:contents, which older Amazon Silk builds mishandle — the logo
   then rendered shifted up from its blue strip. Plain flexbox works in every
   browser. flex:1 gives the link a definite width so the image's percentage
   max-width resolves cleanly and stays centered. */
.site-header .brand-home {
  display: flex;
  flex: 1 1 auto;
  justify-content: center;
  align-items: center;
}

.site-header .brand-logo {
  display: block; /* block (not inline) so there's no baseline gap under it */
  max-width: min(360px, 90%);
  height: auto;
  cursor: pointer;
}

.site-header .eyebrow {
  margin-top: 6px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.9), 0 0 4px rgba(0,0,0,.6);
}

.site-footer {
  text-align: center;
  margin-top: 18px;
  padding: 0 12px;
  color: #fff;
  font-size: .7rem;
  line-height: 1.5;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

.game-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.game-nav-link {
  color: #fff;
  text-decoration: none;
  font-size: .75rem;
  font-weight: bold;
  letter-spacing: .03em;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10,36,106,.82);
  text-shadow: 0 1px 2px rgba(0,0,0,.7);
  border: 1px solid rgba(255,255,255,.35);
}

.game-nav-link:hover {
  background: rgba(20,60,150,.9);
}

.game-nav-link.is-active {
  background: #ffd23f;
  color: #6b4e00;
  border: 2px solid #000;
  text-shadow: none;
  box-shadow: 0 2px 5px rgba(0,0,0,.4);
}

/* Attention glow for the museum pill on the landing page (cyan accent to
   match the museum viewer). Pulses gently; static for reduced-motion users. */
.game-nav-link.glow {
  animation: pill-glow 1.8s ease-in-out infinite;
}

@keyframes pill-glow {
  0%, 100% {
    box-shadow: 0 0 5px rgba(69,231,255,.6), 0 0 10px rgba(69,231,255,.35);
    border-color: rgba(120,240,255,.75);
  }
  50% {
    box-shadow: 0 0 14px rgba(69,231,255,1), 0 0 28px rgba(69,231,255,.6);
    border-color: rgba(180,248,255,1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-nav-link.glow {
    animation: none;
    box-shadow: 0 0 12px rgba(69,231,255,.7);
    border-color: rgba(120,240,255,.85);
  }
}

/* Inline links inside the win dialog message (variant B: try again / view leaderboard) */
.win-link {
  color: var(--link);
  text-decoration: underline;
  font-weight: bold;
  cursor: pointer;
}
.win-link:hover { color: #1a1aff; }

/* ---- window chrome ---- */
.aim-window,
.im-window {
  width: 100%;
  background: var(--chrome);
  border: 1px solid #4a4a4a;
  border-radius: 5px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.aim-window {
  position: relative;
}

/* ---- sign-on toast: brief "X has signed on!" popup, classic AIM style ---- */
.signon-toast-container {
  position: absolute;
  right: 10px;
  bottom: 34px;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  pointer-events: none;
  z-index: 60;
}

.signon-toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 200px;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid #7f9db9;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  font-size: 12px;
  color: var(--ink);
  animation: toast-in .22s ease-out, toast-out .3s ease-in 1.9s forwards;
}

.signon-toast img {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  object-fit: cover;
  flex-shrink: 0;
}

.signon-toast strong { color: var(--online); }

@keyframes toast-in {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-6px); }
}

.title-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 5px;
  background: linear-gradient(180deg, var(--title-end), var(--title-start));
  color: #fff;
}

.title-bar-icon {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  background: #ffd23f;
  border-radius: 50%;
  font-size: 14px;
  color: #6b4e00;
}

.title-bar-text {
  flex: 1;
  font-weight: bold;
  font-size: 14px;
  letter-spacing: .01em;
}

.title-bar-controls {
  display: flex;
  gap: 3px;
}

.tb-btn {
  width: 18px;
  height: 16px;
  display: grid;
  place-items: center;
  background: var(--chrome);
  color: #000;
  border: 1px solid #fff;
  border-right-color: #4a4a4a;
  border-bottom-color: #4a4a4a;
  font-size: 12px;
  line-height: 1;
}

.tb-close { font-weight: bold; }

.menu-bar {
  display: flex;
  gap: 16px;
  padding: 3px 8px;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-dark);
  font-size: 14px;
  color: var(--ink-muted);
}

/* ---- layout ---- */
.aim-body {
  display: grid;
  grid-template-columns: 190px 1fr;
  min-height: 480px;
}

.buddy-panel {
  background: #fff;
  border-right: 1px solid var(--chrome-dark);
  padding: 8px 0;
  overflow-y: auto;
}

.buddy-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 8px;
  border-bottom: 1px solid #ddd;
  margin-bottom: 6px;
  font-weight: bold;
  font-size: 14px;
}

.status-pill {
  font-size: 12px;
  font-weight: normal;
  color: var(--online);
}

.group-label {
  padding: 4px 10px;
  font-size: 13px;
  font-weight: bold;
  color: var(--ink-muted);
}

.disclosure { display: inline-block; width: 10px; }

.buddy-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
}

.buddy-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 24px;
  font-size: 14px;
}

.buddy-list li img {
  width: 18px;
  height: 18px;
  object-fit: cover;
  border-radius: 3px;
}

.buddy-list li.online { color: var(--link); }
.buddy-list li.offline { color: var(--offline); }

/* ---- "signing on" effect for a buddy that just matched ---- */
@keyframes buddy-sign-on {
  0% { transform: translateX(-16px); opacity: 0; background-color: #fff2a8; }
  50% { transform: translateX(0); opacity: 1; background-color: #fff2a8; }
  100% { background-color: transparent; }
}

.buddy-list li.is-signing-on {
  animation: buddy-sign-on .8s ease-out;
  border-radius: 4px;
}

@keyframes buddy-dot-ping {
  0% { box-shadow: 0 0 0 0 rgba(42,138,42,.55); }
  70% { box-shadow: 0 0 0 9px rgba(42,138,42,0); }
  100% { box-shadow: 0 0 0 0 rgba(42,138,42,0); }
}

.buddy-list li.is-signing-on .buddy-dot {
  animation: buddy-dot-ping 1s ease-out;
}

.buddy-list .buddy-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.buddy-list li.online .buddy-dot { background: var(--online); }
.buddy-list li.offline .buddy-dot { background: var(--offline); }

.buddy-list .empty-hint {
  padding: 3px 10px 3px 24px;
  color: #999;
  font-size: 13px;
  font-style: italic;
}

.game-panel {
  padding: 16px 18px 20px;
  background: var(--chrome);
}

/* ---- hero ---- */
.hero { text-align: center; margin: 4px 0 14px; }

.eyebrow {
  color: var(--title-start);
  font-size: .68rem;
  font-weight: bold;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  letter-spacing: -.02em;
  color: var(--title-start);
}

.tagline { color: var(--ink-muted); margin: 4px 0 0; font-size: .85rem; }

/* ---- controls ---- */
.control-panel {
  display: flex;
  gap: 10px;
  align-items: end;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.control-panel label {
  display: grid;
  gap: 4px;
  color: var(--ink-muted);
  font-size: .72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.checkbox-toggle {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  align-self: center;
  color: var(--ink-muted);
  font-size: .72rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .04em;
  cursor: pointer;
}

.toggle-icon {
  flex-shrink: 0;
  display: block;
}

.checkbox-toggle input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

#time.is-urgent {
  color: #a32d2d;
  animation: time-urgent-pulse 1s ease-in-out infinite;
}

@keyframes time-urgent-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

select {
  color: var(--ink);
  background: #fff;
  border: 1px solid #7f9db9;
  border-radius: 2px;
  padding: 6px 8px;
}

.primary-button,
.secondary-button {
  border-radius: 3px;
  padding: 7px 14px;
  font-weight: bold;
  cursor: pointer;
  border: 1px solid #7f9db9;
  box-shadow: inset 1px 1px 0 #fff;
}

.primary-button {
  color: #fff;
  background: linear-gradient(180deg, #4f92d6, #1c5fa8);
  border-color: #14417a;
}

.primary-button:hover { filter: brightness(1.06); }

.secondary-button {
  color: var(--ink);
  background: linear-gradient(180deg, #fdfdfd, #e4e4e4);
}

.secondary-button[aria-pressed="false"] {
  color: #999;
  background: #ececec;
}

/* ---- status bar ---- */
.status-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #fff;
  border: 1px solid var(--chrome-dark);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 14px;
}

.status-bar > div { padding: 8px; text-align: center; }
.status-bar > div + div { border-left: 1px solid #ddd; }

.status-label {
  display: block;
  color: var(--ink-muted);
  font-size: .64rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 2px;
}

.status-bar strong { font-size: 1rem; color: var(--title-start); }

/* ---- board / cards ---- */
.game-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  perspective: 1000px;
}

.card {
  display: block;
  position: relative;
  aspect-ratio: 1 / 1;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  perspective: 800px;
  -webkit-tap-highlight-color: transparent;
}

.card-inner {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .3s ease;
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 9%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #7f9db9;
  box-shadow: inset 1px 1px 0 #fff;
}

.card-back {
  background-image: url("assets/ui/card-back.png");
  background-size: cover;
  background-position: center;
}

/* ---- New Game deal-in: cards fly/fade into place staggered by index ---- */
.card {
  animation: deal-in .3s ease backwards;
}

@keyframes deal-in {
  0% { opacity: 0; transform: translateY(-24px) scale(.85); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.card-front {
  transform: rotateY(180deg);
  background: #fff;
}

.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.card.is-matched { pointer-events: none; }

.card.is-matched .card-front {
  animation: matched .5s ease forwards;
}

@keyframes matched {
  50% { transform: rotateY(180deg) scale(1.06); }
  100% { transform: rotateY(180deg) scale(.92); opacity: .3; }
}

.instructions {
  text-align: center;
  color: var(--ink-muted);
  font-size: .78rem;
  line-height: 1.4;
  margin: 14px auto 0;
  max-width: 520px;
}

/* ---- bottom status bar ---- */
.aim-status-bar {
  padding: 4px 10px;
  background: var(--chrome);
  border-top: 1px solid var(--chrome-dark);
  font-size: 13px;
  color: var(--ink-muted);
  font-style: italic;
}

/* ---- IM win dialog ---- */
.im-window {
  border: 1px solid #4a4a4a;
  border-radius: 5px;
  padding: 0;
  color: var(--ink);
  background: var(--chrome);
  width: min(92vw, 420px);
  box-shadow: var(--shadow);
}

.im-window::backdrop {
  background: rgba(0,0,0,.35);
}

.dialog-inner {
  padding: 16px;
  background: var(--chrome);
}

.im-log {
  background: #fff;
  border: 1px inset #7f9db9;
  border-radius: 2px;
  box-shadow: inset 1px 1px 4px rgba(0,0,0,.2);
  padding: 10px 12px;
  margin: 0 0 16px;
  font-size: 15px;
  line-height: 1.6;
  color: #000;
}

.im-from-name {
  color: #cc0000;
  font-weight: bold;
  font-size: 18px;
  /* Buddy name keeps the classic AIM serif; the message reverts to the
     easier-to-read sans body font. */
  font-family: "Times New Roman", Times, serif;
}

/* Red, bold colon after the buddy's name; message sits on the line below. */
.im-from-name::after {
  content: ":";
}

.im-timestamp {
  display: none;
}

/* ---- leaderboard dialog: retro arcade high-score screen ---- */
.leaderboard-dialog {
  width: min(380px, 92vw);
}

.leaderboard-dialog .dialog-inner {
  background: #0a0a1a;
  padding: 16px 14px;
}

.leaderboard-field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.leaderboard-field label {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 9px;
  color: #45e7ff;
  text-shadow: 0 0 4px rgba(69,231,255,.6);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.leaderboard-field select {
  background: #000;
  color: #ffd23f;
  border: 2px solid #45e7ff;
  border-radius: 2px;
  padding: 9px 8px;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 13px;
}

.leaderboard-field select option {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 15px;
  padding: 6px;
}

.leaderboard-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  border: 2px solid #45e7ff;
  border-radius: 3px;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 48vh;
  box-shadow: 0 0 12px rgba(69,231,255,.35);
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: #000;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 10px;
  color: #fff;
}

.leaderboard-list li:nth-child(even) {
  background: #0e0e22;
}

.leaderboard-list li:first-child {
  background: linear-gradient(90deg, rgba(255,210,63,.18), transparent);
  color: #ffd23f;
  text-shadow: 0 0 6px rgba(255,210,63,.75);
}

.leaderboard-rank {
  color: #666;
}

.leaderboard-list li:first-child .leaderboard-rank {
  color: #ffd23f;
}

.leaderboard-list li.is-you {
  position: relative;
  z-index: 1;
  animation: you-glow 1.4s ease-in-out infinite;
}

@keyframes you-glow {
  0%, 100% { box-shadow: inset 0 0 0 2px #45e7ff, 0 0 6px rgba(69,231,255,.45); }
  50% { box-shadow: inset 0 0 0 2px #45e7ff, 0 0 16px rgba(69,231,255,.9); }
}

.leaderboard-initials {
  display: inline-flex;
  align-items: center;
  color: #ff2c91;
  text-shadow: 0 0 4px rgba(255,44,145,.7);
  letter-spacing: .1em;
}

.tc-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  color: #ffd23f;
  cursor: help;
  filter: drop-shadow(0 0 1px rgba(255,210,63,.6));
}

.tc-badge svg {
  display: block;
}

.leaderboard-time {
  font-variant-numeric: tabular-nums;
}

.leaderboard-moves {
  color: #888;
  font-size: 8px;
}

.leaderboard-empty {
  text-align: center;
  color: #45e7ff;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 10px;
  line-height: 1.6;
  margin: 20px 0;
}

.leaderboard-dialog .dialog-actions {
  justify-content: center;
}

/* Animated "connecting…" ellipsis: the three dots brighten in sequence for a
   cascading-fade / twinkle while we wait on the leaderboard server. */
.loading-ellipsis {
  display: inline-block;
  margin-left: 1px;
  letter-spacing: 2px;
}
.loading-ellipsis i {
  font-style: normal;
  opacity: .2;
  animation: ellipsis-fade 1.4s infinite ease-in-out;
}
.loading-ellipsis i:nth-child(2) { animation-delay: .2s; }
.loading-ellipsis i:nth-child(3) { animation-delay: .4s; }

@keyframes ellipsis-fade {
  0%, 70%, 100% { opacity: .2; }
  35% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-ellipsis i { animation: none; opacity: 1; }
}

/* ---- arcade-style 3-letter initials entry (shown after a win) ---- */
.score-submit {
  background: #0a0a1a;
  border: 2px solid #45e7ff;
  border-radius: 4px;
  padding: 14px 12px;
  margin: 4px 0 16px;
  box-shadow: 0 0 12px rgba(69,231,255,.35);
}

.score-submit label {
  display: block;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 9px;
  color: #45e7ff;
  text-shadow: 0 0 4px rgba(69,231,255,.6);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 10px;
  line-height: 1.6;
}

.initials-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.initial-box {
  width: 42px;
  height: 48px;
  padding: 0;
  margin: 0;
  line-height: 48px;
  text-align: center;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 18px;
  font-weight: normal;
  text-transform: uppercase;
  color: #ffd23f;
  text-shadow: 0 0 6px rgba(255,210,63,.7);
  background: #000;
  border: 2px solid #45e7ff;
  border-radius: 3px;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.initials-input button {
  background: #000;
  color: #ffd23f;
  border: 2px solid #ffd23f;
  border-radius: 3px;
  padding: 10px 12px;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .04em;
  box-shadow: 0 0 8px rgba(255,210,63,.4);
}

.initials-input button:hover:not(:disabled) {
  box-shadow: 0 0 14px rgba(255,210,63,.7);
}

.initials-input button:disabled {
  opacity: .5;
  box-shadow: none;
}

.score-submit-status {
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 9px;
  line-height: 1.6;
  color: #7CFC7C;
  margin: 10px 0 0;
  min-height: 14px;
}

.score-submit-status.is-error {
  color: #ff6b6b;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 640px) {
  html, body {
    background-attachment: scroll;
  }

  .aim-body {
    grid-template-columns: 1fr;
  }

  .buddy-panel {
    order: 2;
    border-right: 0;
    border-bottom: 1px solid var(--chrome-dark);
    max-height: 160px;
  }

  .game-panel {
    order: 1;
  }

  .control-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button, .secondary-button { width: 100%; }
}
