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

:root {
  --bg:            #0f0f10;
  --surface:       #1c1c1e;
  --border:        #2c2c2e;
  --border-fill:   #48484a;
  --key-bg:        #3a3a3c;
  --muted:         #6e6e73;
  --correct:       #0d9488;
  --correct-glow:  rgba(13, 148, 136, 0.4);
  --present:       #c026d3;
  --present-glow:  rgba(192, 38, 211, 0.35);
  --absent:        #2c2c2e;
  --text:          #f5f5f7;
}

body {
  font-family: 'Montserrat', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---- Header ---- */
header {
  position: relative;
  width: 100%;
  max-width: 500px;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#btn-install {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid #48484a;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: #f5f5f7;
  color: var(--text);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#btn-install:hover { border-color: var(--muted); background: var(--surface); }
#btn-install[hidden] { display: none; }

h1 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.75rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}

/* ---- Past-puzzle banner ---- */
#past-puzzle-banner {
  width: 100%;
  max-width: 500px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
}
#past-puzzle-banner a { color: var(--muted); text-decoration: underline; }
#past-puzzle-banner[hidden] { display: none; }

/* ---- Already-done banner ---- */
#already-done-banner {
  width: 100%;
  max-width: 500px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

#already-done-banner[hidden] { display: none; }

/* ---- Friend invite bar ---- */
#friend-invite-bar {
  width: 100%;
  max-width: 500px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}
#friend-invite-bar[hidden] { display: none; }
.friend-invite-btns { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
#btn-invite-accept {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: border-color 0.15s;
}
#btn-invite-accept:hover { border-color: var(--muted); }
#btn-invite-dismiss {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 1rem;
  line-height: 1;
}
#btn-invite-dismiss:hover { color: var(--text); }

#btn-view-result {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: border-color 0.15s;
}

#btn-view-result:hover { border-color: var(--muted); }

/* ---- Timer bar ---- */
#timer-bar {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  padding: 8px 0 4px;
  text-align: center;
  letter-spacing: 0.02em;
}

#header-countdown {
  color: var(--correct);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---- Board ---- */
#board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  min-height: 0;
  padding: 8px 0;
}

#board {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.row { display: flex; gap: 5px; }

.tile {
  position: relative;
  width: 62px;
  height: 62px;
  border: 2px solid var(--border);
  border-radius: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  transition: border-color 0.1s;
}

.tile[data-letter] { border-color: var(--border-fill); }

/* Glyph indicator (top-left) — distinguishes states without relying on color */
.tile.correct::before,
.tile.present::before {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.9;
}
.tile.correct::before { content: '✓'; }
.tile.present::before { content: '•'; }

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
  box-shadow: 0 0 14px var(--correct-glow);
}
.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
  box-shadow: 0 0 14px var(--present-glow);
}
.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: var(--muted);
}

.tile.pop { animation: pop 0.1s ease; }

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

.row.shake { animation: shake 0.5s ease; }

@keyframes shake {
  0%,100%              { transform: translateX(0); }
  10%,30%,50%,70%,90%  { transform: translateX(-5px); }
  20%,40%,60%,80%      { transform: translateX(5px); }
}

.row.bounce .tile { animation: bounce 0.1s ease forwards; }
.row.bounce .tile:nth-child(1) { animation-delay: 0.0s; }
.row.bounce .tile:nth-child(2) { animation-delay: 0.1s; }
.row.bounce .tile:nth-child(3) { animation-delay: 0.2s; }
.row.bounce .tile:nth-child(4) { animation-delay: 0.3s; }
.row.bounce .tile:nth-child(5) { animation-delay: 0.4s; }

@keyframes bounce {
  0%,100% { transform: translateY(0); }
  40%     { transform: translateY(-18px); }
}

/* ---- Keyboard ---- */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 500px;
  padding: 0 8px 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  height: 58px;
  flex: 1;
  max-width: 43px;
  border-radius: 10px;
  border: none;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  background: var(--key-bg);
  color: var(--text);
  transition: background 0.15s, transform 0.08s;
  touch-action: manipulation;
}

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

.key.wide    { max-width: 65px; font-size: 0.72rem; padding: 0 4px; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent  { background: var(--absent); color: var(--muted); }

/* ---- Toasts ---- */
#toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 500;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: 100px;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  animation: toastIn 2s ease forwards;
}

@keyframes toastIn {
  0%   { opacity: 0; transform: translateY(-6px) scale(0.95); }
  12%  { opacity: 1; transform: translateY(0) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- New word ready banner ---- */
#new-word-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--correct);
  color: #fff;
  padding: 10px 12px 10px 20px;
  border-radius: 100px;
  box-shadow: 0 6px 24px var(--correct-glow);
  z-index: 600;
  max-width: calc(100vw - 32px);
  animation: newWordIn 0.35s ease forwards;
}

.new-word-text {
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
}

.new-word-play {
  background: #fff;
  color: var(--correct);
  border: none;
  border-radius: 100px;
  padding: 6px 16px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
}
.new-word-play:hover { transform: scale(1.05); }
.new-word-play:active { opacity: 0.85; }

.new-word-dismiss {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  opacity: 0.8;
}
.new-word-dismiss:hover { opacity: 1; }

@keyframes newWordIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- Modal ---- */
#modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 400;
  justify-content: center;
  align-items: center;
}

#modal.active { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px 28px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal-box h2 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.modal-subtitle    { color: var(--muted); font-size: 0.82rem; font-weight: 500; margin-bottom: 4px; }

.modal-timer-label { color: var(--muted); font-size: 0.78rem; font-weight: 500; margin-bottom: 4px; }

#solve-time {
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.08em;
  margin-bottom: 20px;
}

#modal-countdown {
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 700;
  color: var(--correct);
  letter-spacing: 0.08em;
  margin-bottom: 24px;
}

#puzzle-number { color: var(--muted); font-size: 0.78rem; font-weight: 500; margin-bottom: 24px; }

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  margin-bottom: 10px;
  transition: filter 0.15s, transform 0.08s;
}

.btn:active { transform: scale(0.98); }
.btn-share  { background: var(--correct); color: #fff; }
.btn-share:hover  { filter: brightness(1.15); }
.btn-close  { background: var(--border); color: var(--text); margin-bottom: 0; }
.btn-close:hover  { filter: brightness(1.35); }

#modal-signup-nudge {
  width: 100%;
  background: rgba(13, 148, 136, 0.12);
  background: color-mix(in srgb, var(--correct) 12%, transparent);
  border: 1px solid rgba(13, 148, 136, 0.4);
  border: 1px solid color-mix(in srgb, var(--correct) 40%, transparent);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 4px;
  text-align: center;
}
.nudge-text {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.4;
}
.btn-signup {
  display: block;
  background: var(--correct);
  color: #fff;
  border-radius: 8px;
  padding: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  transition: filter 0.15s;
}
.btn-signup:hover { filter: brightness(1.15); }

/* ---- Install bottom sheet ---- */
#install-sheet {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 401;
  align-items: flex-end;
  justify-content: center;
}
#install-sheet.active { display: flex; }

.install-sheet-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px max(28px, env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  text-align: center;
  animation: sheetUp 0.25s cubic-bezier(0.32,0.72,0,1) forwards;
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.install-sheet-icon {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  margin-bottom: 12px;
}
.install-sheet-title {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.install-sheet-desc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 20px;
  line-height: 1.5;
}
#install-sheet-ios { margin-bottom: 20px; text-align: left; }
.install-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 10px;
  color: var(--text);
}
.install-step-text { flex: 1; min-width: 0; }
.install-step-num {
  flex-shrink: 0;
  background: var(--correct);
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.install-share-icon {
  font-style: normal;
  font-size: 1rem;
}

/* ---- Account button ---- */
#btn-account {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid #48484a;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: #f5f5f7;
  color: var(--text);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#btn-account:hover        { border-color: var(--muted); background: var(--surface); }
#btn-account.signed-in    { border-color: var(--correct); color: var(--correct); }
#btn-account svg, #btn-install svg { pointer-events: none; display: block; }

/* ---- Profile page layout ---- */
body.profile-page {
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

#profile-container {
  width: 100%;
  max-width: 500px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.profile-page-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

body.profile-page .friends-list,
body.profile-page .history-list {
  max-height: 360px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
}

#btn-back {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: var(--text);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
#btn-back:hover { border-color: var(--muted); background: var(--surface); }

/* ---- Auth tabs ---- */
.auth-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 16px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.auth-tab.active { background: var(--border); color: var(--text); }

/* ---- Inputs ---- */
.auth-input {
  display: block;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 12px 14px;
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.15s;
}
.auth-input:focus   { border-color: var(--border-fill); }
.auth-input[hidden] { display: none; }

/* ---- Auth error ---- */
.auth-error {
  background: #1a0d0d;
  border: 1px solid #5c1f1f;
  border-radius: 8px;
  color: #ff8080;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 10px 12px;
  margin-bottom: 12px;
  text-align: left;
}
.auth-error[hidden] { display: none; }

/* ---- Profile ---- */
.profile-username { font-size: 1.4rem; letter-spacing: 0.06em; margin-bottom: 4px; }

/* ---- Friends section ---- */
.friends-section    { margin: 20px 0 16px; text-align: left; }
.friends-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.friends-header     { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.invite-link-btn {
  background: transparent;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.invite-link-btn:hover { color: var(--text); border-color: var(--text); }

.add-friend-row   { display: flex; gap: 8px; margin-bottom: 12px; }
.add-friend-input { flex: 1; margin-bottom: 0; }
.add-friend-btn {
  background: var(--correct);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0 16px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: filter 0.15s;
  white-space: nowrap;
}
.add-friend-btn:hover    { filter: brightness(1.15); }
.add-friend-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.friends-subheader {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--present);
  margin-bottom: 8px;
  margin-top: 2px;
}

.friend-requests-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.friend-request-item {
  background: var(--bg);
  border: 1px solid var(--present);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.friend-request-btns { display: flex; gap: 6px; flex-shrink: 0; }

.friend-accept-btn {
  background: var(--correct);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: filter 0.15s;
}
.friend-accept-btn:hover { filter: brightness(1.15); }

.friend-decline-btn {
  background: transparent;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color 0.15s, border-color 0.15s;
}
.friend-decline-btn:hover { color: #ff6b6b; border-color: #ff6b6b; }

.friends-list    { max-height: 240px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 8px; }
.friends-status  { color: var(--muted); font-size: 0.8rem; text-align: center; padding: 12px 0; }

.friend-item     { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.friend-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.friend-username { font-size: 0.88rem; font-weight: 700; color: var(--text); }

.friend-remove-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s;
}
.friend-remove-btn:hover { color: #ff6b6b; }

.friend-followback-btn {
  background: var(--correct);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  transition: opacity 0.15s;
}
.friend-followback-btn:hover { opacity: 0.85; }

.friend-score    { display: block; font-size: 0.82rem; font-weight: 700; color: var(--correct); }
.friend-time     { font-weight: 500; color: var(--muted); margin-left: 4px; }
.friend-no-result { font-size: 0.78rem; color: var(--muted); font-style: italic; }

/* ---- History ---- */
.history-list {
  max-height: 260px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.history-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.history-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.hist-id   { font-size: 0.75rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.hist-score { font-size: 0.92rem; font-weight: 700; white-space: nowrap; }
.hist-score.won  { color: var(--correct); }
.hist-score.lost { color: #ff6b6b; }
.hist-time { font-size: 0.75rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-date { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

.history-share-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-fill);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 6px 12px;
  min-height: 34px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}
.history-share-btn:hover { color: var(--text); border-color: var(--text); }

.hist-friends {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.hist-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border-radius: 5px;
  padding: 3px 7px;
  white-space: nowrap;
}
.hist-badge b    { color: var(--text); }
.hist-badge.muted { opacity: 0.45; }

/* ---- Friends activity feed ---- */
.friend-item--compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
}

#activity-list {
  max-height: 360px;
  overflow-y: auto;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
}

.activity-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}

.activity-more {
  margin-top: 2px;
}
.activity-more-toggle {
  list-style: none;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 0 2px;
  transition: color 0.15s;
}
.activity-more-toggle::-webkit-details-marker { display: none; }
.activity-more-toggle:hover { color: var(--text); }
.activity-more .more-hide { display: none; }
.activity-more[open] .more-show { display: none; }
.activity-more[open] .more-hide { display: inline; }

.activity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.activity-puzzle-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.activity-timestamp {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
}

.activity-my-score {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 700;
}

.activity-my-score .hist-score,
.activity-friend-row .hist-score {
  font-size: 0.88rem;
  min-width: 2.2rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.activity-my-score .friend-time,
.activity-friend-row .friend-time {
  font-size: 0.8rem;
  width: 2.6rem;
  margin-left: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.activity-play-btn {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--correct);
  text-decoration: none;
  background: rgba(13, 148, 136, 0.1);
  background: color-mix(in srgb, var(--correct) 10%, transparent);
  border: 1px solid rgba(13, 148, 136, 0.35);
  border: 1px solid color-mix(in srgb, var(--correct) 35%, transparent);
  border-radius: 6px;
  padding: 3px 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}
.activity-play-btn:hover { background: rgba(13, 148, 136, 0.22); background: color-mix(in srgb, var(--correct) 22%, transparent); }

.activity-friend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.act-friend-name {
  flex: 1;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.act-playing {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--present);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  font-style: italic;
}

.activity-load-more,
.history-load-more {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border-fill);
  border-radius: 10px;
  color: var(--muted);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  margin-top: 2px;
  transition: color 0.15s, border-color 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.activity-load-more:hover,
.history-load-more:hover { color: var(--text); border-color: var(--text); }

/* ---- Social collapsible panels ---- */
.social-collapse {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 10px;
  overflow: hidden;
}

.social-collapse-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.social-collapse-summary::marker                  { display: none; }
.social-collapse-summary::-webkit-details-marker  { display: none; }
.social-collapse-summary::after {
  content: '›';
  font-size: 1.1rem;
  color: var(--muted);
  margin-left: auto;
  transition: transform 0.2s;
}
details[open] > .social-collapse-summary::after { transform: rotate(90deg); }

.social-collapse-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.social-collapse-count {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  opacity: 0.6;
}

.social-collapse-body {
  border-top: 1px solid var(--border);
  gap: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
body.profile-page .social-collapse-body { max-height: 200px; }

.social-collapse-body .friend-item {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 10px 14px;
}
.social-collapse-body .friend-item:last-child { border-bottom: none; }

.social-collapse-body .friends-status {
  padding: 10px 14px;
  text-align: left;
}

/* ---- Leaderboard ---- */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.leaderboard-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.leaderboard-item.leaderboard-me {
  border-color: var(--correct);
  background: #0f1a1a;
  background: color-mix(in srgb, var(--correct) 8%, var(--bg));
}

.leaderboard-rank {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  width: 18px;
  flex-shrink: 0;
  text-align: center;
}

.leaderboard-name {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-name.is-me { color: var(--correct); }

.leaderboard-stats {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.lb-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 32px;
}

.lb-val   { font-size: 0.88rem; font-weight: 700; color: var(--text); }
.lb-label { font-size: 0.6rem;  font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- Loading overlay ---- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  transition: opacity 0.25s ease;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--correct);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* ---- Responsive: short screens ---- */
@media (max-height: 710px) {
  header        { padding: 10px 16px; }
  h1            { font-size: 1.5rem; }
  #board-container { padding: 10px 0; }
  #board        { gap: 4px; }
  .row          { gap: 4px; }
  .tile         { width: 56px; height: 56px; font-size: 1.75rem; }
  #keyboard     { gap: 6px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .key          { height: 52px; }
}

@media (max-height: 580px) {
  header        { padding: 8px 16px; }
  h1            { font-size: 1.3rem; }
  #timer-bar    { padding: 4px 0 2px; }
  #board-container { padding: 6px 0; }
  #board        { gap: 3px; }
  .row          { gap: 3px; }
  .tile         { width: 47px; height: 47px; font-size: 1.4rem; }
  #keyboard     { gap: 5px; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .key          { height: 43px; }
}
