: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: 18px 12px 28px;
  display: flex;
  justify-content: center;
}

button, select { font: inherit; }

.page {
  width: min(880px, 100%);
}

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

.site-header .brand-logo {
  max-width: min(360px, 90%);
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.45));
}

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

.game-nav {
  display: flex;
  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-color: #ffd23f;
  text-shadow: none;
}

/* ---- 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;
}

.time-challenge-toggle {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  align-self: center;
}

.time-challenge-toggle input {
  width: 16px;
  height: 16px;
}

#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: 11%;
  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;
}

.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: #fff;
}

.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: 13px;
  line-height: 1.6;
  color: #000;
}

.im-from-name {
  color: #cc0000;
  font-weight: bold;
}

.im-timestamp {
  color: #888;
  font-size: 11px;
}

/* ---- 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: 7px 8px;
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 10px;
}

.leaderboard-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  border: 2px solid #45e7ff;
  border-radius: 3px;
  overflow: hidden;
  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-initials {
  color: #ff2c91;
  text-shadow: 0 0 4px rgba(255,44,145,.7);
  letter-spacing: .1em;
}

.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;
}

/* ---- 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 {
    border-right: 0;
    border-bottom: 1px solid var(--chrome-dark);
    max-height: 160px;
  }

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

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