:root {
  --bg:        #eaeef6;
  --bg-2:      #f6f8fc;
  --paper:     #ffffff;
  --ink:       #1f2547;
  --ink-soft:  #5b6486;
  --line:      #e3e7f0;
  --line-2:    #ccd3e4;
  --navy:      #2b2f77;
  --navy-2:    #3a3f95;
  --yellow:    #ffd60a;
  --yellow-d:  #f5c400;
  --good:      #16a34a;
  --warn:      #d97706;
  --bad:       #dc2626;
  --radius:    18px;
  --shadow:    0 6px 22px rgba(43, 47, 119, 0.10);
  --shadow-lg: 0 14px 40px rgba(43, 47, 119, 0.18);
  --font:      "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: #fff;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  touch-action: manipulation;
}
/* iOS auto-zooms inputs under 16px on focus — keep form fields at 16px+ */
input, select, textarea { font-size: 16px; }
a { color: var(--navy-2); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

/* ---- App shell ---- */
.rp-shell { max-width: 1120px; margin: 0 auto; padding: 18px 20px 72px; }

.rp-topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 4px 2px; margin-bottom: 22px;
}
.rp-topbar-home { position: relative; justify-content: center; }
.rp-topbar-home .rp-spacer { display: none; }
.rp-topbar-home #account-slot { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }
.rp-brand { display: flex; align-items: center; gap: 11px; font-weight: 900; font-size: 23px; color: var(--navy); letter-spacing: -0.5px; }
.rp-logo-img { height: 104px; width: auto; max-width: 80vw; display: block; }
@media (max-width: 600px) {
  .rp-logo-img { height: 72px; }
  .rp-topbar-home { flex-direction: column; gap: 12px; }
  .rp-topbar-home #account-slot { position: static; transform: none; }
}
.rp-brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--navy); color: var(--yellow);
  display: grid; place-items: center; font-size: 18px;
}
.rp-brand small { color: #6c5a00; font-weight: 700; font-size: 12px; letter-spacing: 0; }
.rp-spacer { flex: 1; }
.rp-back { display: inline-flex; align-items: center; gap: 6px; color: var(--navy); font-weight: 800; font-size: 14px;
  padding: 7px 13px; border: 1.5px solid var(--line-2); border-radius: 10px; background: var(--paper); }
.rp-back:hover { text-decoration: none; opacity: 1; border-color: var(--navy); background: var(--bg-2); }
/* Larger tap targets for in-game header controls on touch devices */
@media (pointer: coarse) {
  .rp-game-head .rp-back { font-size: 16px; padding: 11px 16px; min-height: 44px; }
  .rp-game-head #account-slot .rp-btn { padding: 12px 18px; font-size: 15px; }
  .rp-game-head .rp-avatar { width: 44px; height: 44px; }
}

/* ---- Hero ---- */
.rp-hero { margin: 4px 2px 24px; }
.rp-hero h1 { font-size: clamp(28px, 5vw, 42px); margin: 0 0 8px; line-height: 1.04; color: var(--navy); letter-spacing: -1px; }
.rp-hero p { color: var(--ink-soft); margin: 0; font-size: 16px; max-width: 60ch; }

/* ---- Buttons ---- */
.rp-btn {
  appearance: none; border: 2px solid var(--line-2); cursor: pointer;
  background: var(--paper); color: var(--ink);
  padding: 9px 16px; border-radius: 12px; font-weight: 800; font-size: 14px;
  font-family: inherit; transition: transform .08s ease, background .15s, border-color .15s, box-shadow .15s;
}
.rp-btn:hover { border-color: var(--navy); }
.rp-btn:active { transform: translateY(1px); }
.rp-btn:disabled { opacity: .5; cursor: default; }
.rp-btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); box-shadow: var(--shadow); }
.rp-btn-primary:hover { background: var(--navy-2); border-color: var(--navy-2); }
.rp-btn-ghost { background: transparent; border-color: transparent; }
.rp-btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.rp-btn-accent { background: var(--g, var(--navy)); color: #fff; border-color: transparent; }

/* ---- Account avatar (opens the profile sheet) ---- */
.rp-avatar { position: relative; flex: none; width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid var(--line-2); background: var(--paper); color: var(--navy);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.rp-avatar:hover { border-color: var(--navy); background: var(--bg-2); }
.rp-avatar svg { display: block; }
.rp-avatar-dot { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--good); border: 2px solid var(--paper); }

/* ---- Profile sheet ---- */
.rp-profile-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.rp-profile-ava { flex: none; width: 48px; height: 48px; border-radius: 50%; background: var(--bg-2);
  border: 2px solid var(--line-2); color: var(--navy); display: inline-flex; align-items: center; justify-content: center; }
.rp-profile-name { font-weight: 800; font-size: 19px; color: var(--ink); }
.rp-profile-sub { font-size: 13px; color: var(--ink-soft); }
.rp-profile-admin { display: inline-flex; margin-bottom: 4px; }
.rp-profile-h { margin: 16px 0 8px; font-size: 14px; color: var(--ink-soft); }
.rp-profile-rule { border: none; border-top: 1px solid var(--line); margin: 18px 0 14px; }
.rp-ok { color: var(--good); font-weight: 700; font-size: 14px; margin: 2px 0 0; }
.rp-btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; width: 100%; }
.rp-btn-danger:hover { filter: brightness(0.94); }

/* ---- Sections / groups ---- */
.rp-group { margin: 8px 0 6px; }
.rp-group-h { display: flex; align-items: center; gap: 10px; margin: 26px 2px 14px; }
.rp-group-h h2 { font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); font-weight: 800; }
.rp-group-h::after { content: ""; flex: 1; height: 2px; background: var(--line); border-radius: 2px; }

/* ---- Game grid ---- */
.rp-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); }
.rp-card {
  position: relative; display: flex; flex-direction: column;
  background: var(--paper); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 18px; min-height: 172px; overflow: hidden;
  border-top: 6px solid var(--g, var(--navy));
  transition: transform .14s ease, box-shadow .14s, border-color .14s;
}
.rp-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.rp-card-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.rp-card-ico {
  width: 50px; height: 50px; border-radius: 13px; display: grid; place-items: center;
  font-size: 26px; flex: none;
  background: color-mix(in srgb, var(--g, var(--navy)) 16%, white);
  border: 2px solid color-mix(in srgb, var(--g, var(--navy)) 35%, white);
}
.rp-card h3 { margin: 0 0 5px; font-size: 19px; color: var(--navy); }
.rp-card p { margin: 0 0 14px; color: var(--ink-soft); font-size: 13.5px; line-height: 1.45; flex: 1; }
.rp-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rp-card-best { font-size: 12.5px; color: var(--ink-soft); }
.rp-card-best b { color: var(--ink); }
.rp-card-play { font-weight: 800; font-size: 13px; color: var(--g, var(--navy)); display: inline-flex; align-items: center; gap: 5px; }
.rp-card a.rp-card-link { position: absolute; inset: 0; z-index: 1; }

/* Hub tools row + compact (icon grid) view */
.rp-hub-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 8px 2px 2px; flex-wrap: wrap; }
.rp-compact .rp-grid { grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 14px; }
.rp-compact .rp-card { min-height: 0; padding: 0; background: none; border: none; box-shadow: none;
  align-items: center; text-align: center; }
.rp-compact .rp-card:hover { transform: none; box-shadow: none; }
.rp-compact .rp-card p, .rp-compact .rp-card-foot,
.rp-compact .rp-fav, .rp-compact .rp-card-badges { display: none; }
.rp-compact .rp-card-top { margin: 0; justify-content: center; width: 100%; }
.rp-compact .rp-card-ico { width: 100%; height: auto; aspect-ratio: 1; font-size: 30px; transition: transform .14s ease; }
.rp-compact .rp-card:hover .rp-card-ico { transform: translateY(-3px); }
.rp-compact .rp-card h3 { font-size: 12.5px; margin: 7px 0 0; line-height: 1.2; color: var(--navy); }
.rp-fav { position: relative; z-index: 2; flex: none; width: 34px; height: 34px;
  display: grid; place-items: center; border: none; background: none; cursor: pointer;
  color: var(--ink-soft); font-size: 25px; line-height: 1; padding: 0;
  transition: transform .12s ease, color .12s ease; }
.rp-fav:hover { transform: scale(1.18); }
.rp-fav.on { color: #f5a623; }
.rp-card-badges { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; z-index: 2; }
.rp-badge { font-size: 10.5px; font-weight: 800; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.rp-badge-daily { background: var(--yellow); color: #6c5a00; }
.rp-badge-streak { background: var(--navy); color: #fff; }
.rp-badge-done { background: var(--good); color: #fff; }

/* ---- Daily strip ---- */
.rp-daily-strip {
  background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 8px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  box-shadow: var(--shadow);
}
[hidden] { display: none !important; }
.rp-daily-strip .lead { font-weight: 800; color: var(--navy); }
.rp-daily-strip .pill { font-size: 13px; font-weight: 700; color: var(--ink-soft); background: var(--bg); border-radius: 999px; padding: 5px 12px; }

/* ---- Modal ---- */
.rp-modal { position: fixed; inset: 0; z-index: 60; display: none; }
.rp-modal.open { display: block; }
.rp-modal-backdrop { position: absolute; inset: 0; background: rgba(31, 37, 71, 0.45); backdrop-filter: blur(3px); }
.rp-modal-card { position: relative; z-index: 1; width: min(420px, calc(100vw - 32px)); margin: 13vh auto 0; background: var(--paper); border: 2px solid var(--navy); border-radius: 18px; padding: 28px 26px 24px; box-shadow: var(--shadow-lg); animation: rp-pop .16s ease; }
@keyframes rp-pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.rp-modal-x { position: absolute; top: 12px; right: 14px; border: none; background: none; color: var(--ink-soft); font-size: 26px; line-height: 1; cursor: pointer; }
.rp-modal-x:hover { color: var(--ink); }
.rp-modal-title { margin: 0 0 6px; font-size: 22px; color: var(--navy); }
.rp-modal-sub { margin: 0 0 20px; color: var(--ink-soft); font-size: 14px; }
.rp-modal-switch { margin: 16px 0 0; text-align: center; color: var(--ink-soft); font-size: 13.5px; }
.rp-link { background: none; border: none; color: var(--navy-2); font: inherit; font-weight: 700; cursor: pointer; padding: 0; }
.rp-link:hover { text-decoration: underline; }
.rp-form { display: flex; flex-direction: column; gap: 14px; }
.rp-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.rp-field input { font: inherit; font-size: 16px; color: var(--ink); font-weight: 600; background: var(--bg-2); border: 2px solid var(--line-2); border-radius: 11px; padding: 12px 14px; outline: none; transition: border-color .15s; }
.rp-field input:focus { border-color: var(--navy); }
.rp-error { color: var(--bad); font-size: 13px; margin: -4px 0 0; font-weight: 600; }

/* ---- Leaderboard ---- */
.rp-board { width: 100%; border-collapse: collapse; font-size: 14px; }
.rp-board th { text-align: left; color: var(--ink-soft); font-weight: 800; font-size: 12px; padding: 6px 10px; text-transform: uppercase; letter-spacing: .04em; }
.rp-board td { padding: 9px 10px; border-top: 2px solid var(--line); }
.rp-board tr.you td { background: color-mix(in srgb, var(--yellow) 35%, white); }
.rp-board .rank { color: var(--ink-soft); width: 38px; font-variant-numeric: tabular-nums; font-weight: 700; }
.rp-board .val { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.rp-empty { color: var(--ink-soft); text-align: center; padding: 22px; font-size: 14px; }

/* ---- Mode toggle ---- */
.rp-toggle { display: inline-flex; background: var(--bg); border: 2px solid var(--line-2); border-radius: 999px; padding: 3px; }
.rp-toggle button { border: none; background: none; font: inherit; font-weight: 800; font-size: 13px; color: var(--ink-soft); padding: 7px 16px; border-radius: 999px; cursor: pointer; }
.rp-toggle button.on { background: var(--navy); color: #fff; }

/* ---- Game page chrome ---- */
.rp-game { max-width: 760px; margin: 0 auto; padding: 16px 16px 80px; }
.rp-game-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.rp-game-title { font-size: 22px; font-weight: 900; margin: 0; color: var(--navy); }
.rp-help-btn { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line-2);
  background: var(--paper); color: var(--navy); font-weight: 900; font-size: 18px; line-height: 1; cursor: pointer; }
.rp-help-btn:hover { border-color: var(--navy); }
@media (pointer: coarse) { .rp-game-head .rp-help-btn { width: 44px; height: 44px; } }
.rp-help-list { margin: 4px 0 0; padding-left: 20px; color: var(--ink); font-size: 14.5px; line-height: 1.6; }
.rp-help-list li { margin-bottom: 8px; }
.rp-req-text { width: 100%; box-sizing: border-box; font: inherit; color: var(--ink); background: var(--paper);
  border: 2px solid var(--line-2); border-radius: 12px; padding: 10px 12px; resize: vertical; margin-bottom: 10px; }
.rp-req-text:focus { border-color: var(--navy); outline: none; }

/* "New version found — refreshing…" notice */
.rp-update-banner { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 9999;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: #fff; color: var(--navy); border: 2px solid var(--navy);
  padding: 13px 26px; border-radius: 14px; box-shadow: var(--shadow-lg);
  font-weight: 700; font-size: 14px; width: min(420px, calc(100% - 24px)); }
.rp-update-spin { width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--line-2); border-top-color: var(--navy); animation: rp-spin .7s linear infinite; }
@keyframes rp-spin { to { transform: rotate(360deg); } }
.rp-scorebar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.rp-stat { background: var(--paper); border: 2px solid var(--line); border-radius: 12px; padding: 7px 16px; min-width: 84px; }
.rp-stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); font-weight: 700; }
.rp-stat .value { font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--navy); }
.rp-controls-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.rp-select { font: inherit; color: var(--ink); background: var(--paper); border: 2px solid var(--line-2); border-radius: 10px; padding: 8px 12px; font-weight: 700; }

.rp-stage { position: relative; min-height: 320px; }

/* Game-over / win overlay */
.rp-overlay { position: absolute; inset: 0; display: none; place-items: center; z-index: 5; background: rgba(255, 255, 255, 0.86); backdrop-filter: blur(2px); border-radius: var(--radius); }
.rp-overlay.show { display: grid; }
.rp-overlay-card { text-align: center; padding: 26px; max-width: 340px; }
.rp-overlay-card h2 { margin: 0 0 6px; font-size: 26px; color: var(--navy); }
.rp-overlay-card .big { font-size: 44px; font-weight: 900; margin: 8px 0; color: var(--navy); }
.rp-overlay-card .msg { color: var(--ink-soft); margin: 0 0 18px; min-height: 20px; font-weight: 600; }
.rp-overlay-card .rp-btn { margin: 4px; }

/* On-screen dpad */
.rp-dpad { display: none; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); gap: 8px; justify-content: center; margin: 18px auto 0; }
.rp-dpad button { border: 2px solid var(--line-2); background: var(--paper); color: var(--navy); border-radius: 12px; font-size: 22px; cursor: pointer; }
.rp-dpad button:active { background: var(--navy); color: #fff; }
.rp-dpad .up { grid-area: 1 / 2; } .rp-dpad .left { grid-area: 2 / 1; }
.rp-dpad .right { grid-area: 2 / 3; } .rp-dpad .down { grid-area: 3 / 2; }
@media (hover: none) and (pointer: coarse) { .rp-dpad.touch { display: grid; } }

.rp-hint { color: var(--ink-soft); font-size: 13px; text-align: center; margin-top: 14px; }
.rp-section-h { display: flex; align-items: center; justify-content: space-between; margin: 28px 2px 14px; gap: 12px; flex-wrap: wrap; }
.rp-section-h h2 { font-size: 18px; margin: 0; color: var(--navy); }
.rp-panel { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.rp-note { color: var(--ink-soft); font-size: 13px; }

/* Shared on-screen keyboard (Wordle/Quordle) */
.rp-kb { display: flex; flex-direction: column; gap: 6px; align-items: center; margin-top: 16px; user-select: none; }
.rp-kb-row { display: flex; gap: 5px; }
.rp-key { min-width: 30px; height: 48px; padding: 0 9px; border-radius: 7px; border: none; background: #c8cfe0; color: var(--ink); font-weight: 800; font-size: 14px; cursor: pointer; }
.rp-key.wide { padding: 0 12px; font-size: 12px; }
.rp-key.correct { background: #16a34a; color: #fff; }
.rp-key.present { background: #eab308; color: #fff; }
.rp-key.absent { background: #8a93a6; color: #fff; }
