/* Rune Merge — a self-contained game space. Deliberately does not share
   draignet.uk's site.css: its own palette, its own type, its own layout
   rules. Only the brand strip ties it back to the studio.

   Layout is built to fit one viewport with no scrolling: .rm-shell is a
   100dvh flex column (brandbar / main / footer), and the board sizes itself
   to whatever vertical space is left rather than pushing the page taller. */

:root{
  --rm-bg:#0a0712;
  --rm-bg-2:#120b1e;
  --rm-panel:#171025;
  --rm-panel-2:#1e1530;
  --rm-line:rgba(255,255,255,.08);
  --rm-line-strong:rgba(255,255,255,.16);

  --rm-text:#ece7f5;
  --rm-text-dim:#a79bc2;
  --rm-text-faint:#6b5f85;

  --rm-arcane:#9b6bff;
  --rm-arcane-hot:#b98cff;
  --rm-ember:#f0a049;
  --rm-ember-hot:#ffbf6b;

  --rm-font-display:"Cinzel",Georgia,"Times New Roman",serif;
  --rm-font-body:"EB Garamond",Georgia,serif;
  --rm-font-mono:"Space Mono","Courier New",monospace;

  --rm-radius:6px;
}

*,*::before,*::after{box-sizing:border-box}

/* Every element this game toggles via .hidden (overlay, keep-playing button,
   score-entry form) sets its own unconditional `display` in a class rule of
   equal specificity to the browser's [hidden]{display:none} default — same
   specificity means source order decides, and this stylesheet loads after
   the UA one, so those classes would otherwise silently win and the element
   would stay visible. This makes [hidden] always win instead. */
[hidden]{display:none!important}

html,body{height:100%}
html{-webkit-text-size-adjust:100%}

body{
  margin:0;
  background:var(--rm-bg);
  color:var(--rm-text);
  font-family:var(--rm-font-body);
  font-size:17px;
  line-height:1.6;
  -webkit-font-smoothing:antialiased;
  overflow:hidden;
  position:relative;
}

img{max-width:100%;display:block}
a{color:inherit;text-decoration:none}

/* ---------- ambient background ---------- */

.rm-field{
  position:fixed;inset:0;z-index:-1;
  background:
    radial-gradient(60% 50% at 20% 8%,rgba(155,107,255,.20),transparent 60%),
    radial-gradient(55% 45% at 85% 12%,rgba(240,160,73,.14),transparent 60%),
    radial-gradient(70% 60% at 50% 100%,rgba(120,60,200,.12),transparent 65%),
    var(--rm-bg);
}
.rm-field::after{
  content:"";position:absolute;inset:0;opacity:.045;pointer-events:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- page shell — fills exactly one viewport ---------- */

.rm-shell{
  display:flex;
  flex-direction:column;
  height:100vh;
  height:100dvh;
}

/* ---------- brand strip ---------- */

.rm-brandbar{
  flex:0 0 auto;
  display:flex;align-items:center;justify-content:space-between;
  padding:14px 24px;
  font-family:var(--rm-font-mono);
  font-size:12px;
  letter-spacing:.04em;
}
.rm-brandbar__brand{
  display:flex;align-items:center;gap:10px;
  color:var(--rm-text-dim);
  transition:color .3s ease;
}
.rm-brandbar__brand img{width:20px;height:20px;opacity:.85}
.rm-brandbar__brand:hover{color:var(--rm-text)}
.rm-brandbar__back{
  color:var(--rm-text-faint);
  transition:color .3s ease;
}
.rm-brandbar__back:hover{color:var(--rm-arcane-hot)}

/* ---------- main / layout ---------- */

.rm-main{
  flex:1 1 auto;
  min-height:0;
  display:flex;
  flex-direction:column;
  max-width:1040px;
  width:100%;
  margin:0 auto;
  padding:6px 24px 12px;
  overflow-y:auto; /* safety net on very short viewports; not the design target */
}

.rm-heading{
  flex:0 0 auto;
  text-align:center;
  margin:0 0 12px;
}
.rm-eyebrow{
  font-family:var(--rm-font-mono);
  font-size:10px;letter-spacing:.28em;text-transform:uppercase;
  color:var(--rm-arcane-hot);
  margin:0 0 6px;
}
.rm-title{
  font-family:var(--rm-font-display);
  font-weight:700;
  font-size:clamp(22px,3.6vw,36px);
  letter-spacing:.05em;
  margin:0;
  color:var(--rm-text);
  text-shadow:
    0 0 18px rgba(155,107,255,.55),
    0 0 46px rgba(240,160,73,.22);
}

.rm-layout{
  flex:1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns:1.15fr .85fr;
  gap:32px;
  align-items:stretch;
}

/* ---------- HUD ---------- */

.rm-play{
  display:flex;
  flex-direction:column;
  min-height:0;
  height:100%;
}

.rm-hud{
  flex:0 0 auto;
  display:flex;
  gap:10px;
  margin-bottom:12px;
  flex-wrap:wrap;
  align-items:center;
}
.rm-score{
  background:var(--rm-panel);
  border:1px solid var(--rm-line);
  border-radius:var(--rm-radius);
  padding:8px 18px;
  text-align:center;
  min-width:86px;
}
.rm-score__label{
  font-family:var(--rm-font-mono);
  font-size:10px;letter-spacing:.2em;text-transform:uppercase;
  color:var(--rm-text-faint);display:block;
}
.rm-score__value{
  font-family:var(--rm-font-mono);
  font-weight:700;
  font-size:20px;color:var(--rm-arcane-hot);
}

/* ---------- buttons ---------- */

.btn{
  display:inline-flex;align-items:center;gap:8px;
  padding:10px 18px;
  font-family:var(--rm-font-mono);
  font-size:11px;font-weight:700;letter-spacing:.12em;text-transform:uppercase;
  border:1px solid var(--rm-line-strong);
  border-radius:var(--rm-radius);
  color:var(--rm-text);
  background:transparent;
  cursor:pointer;
  transition:all .3s ease;
}
.btn:hover{border-color:var(--rm-arcane);color:var(--rm-arcane-hot);transform:translateY(-1px)}
.btn--primary{
  background:linear-gradient(180deg,var(--rm-arcane-hot),var(--rm-arcane));
  border-color:transparent;
  color:#150a2b;
  box-shadow:0 10px 28px -12px rgba(155,107,255,.6);
}
.btn--primary:hover{color:#150a2b;filter:brightness(1.1)}
.btn--ghost{border-color:var(--rm-line)}

/* ---------- board ---------- */

.rm-board{
  position:relative;
  flex:1 1 auto;
  min-height:0;
  width:auto;
  height:auto;
  max-width:100%;
  max-height:100%;
  aspect-ratio:1;
  margin:0 auto;
}
.rm-grid{
  position:relative;
  display:grid;
  grid-template-columns:repeat(4,1fr);
  grid-template-rows:repeat(4,1fr);
  gap:8px;
  width:100%;height:100%;
  padding:10px;
  background:var(--rm-panel);
  border:1px solid var(--rm-line-strong);
  border-radius:var(--rm-radius);
  box-shadow:inset 0 0 0 6px rgba(0,0,0,.25),inset 0 2px 20px rgba(0,0,0,.4);
  outline:none;
}
.rm-grid:focus-visible{outline:2px solid var(--rm-arcane);outline-offset:4px}

.rm-cell{
  background:rgba(255,255,255,.03);
  border-radius:4px;
}

/* Absolutely positioned (not CSS Grid-placed) so left/top can actually
   transition — grid-column/grid-row placement isn't a smoothly animatable
   property, which was why tiles used to vanish and reappear instead of
   sliding. Being position:absolute also takes these out of the grid's own
   auto-placement, so the 16 .rm-cell background tiles are unaffected. */
.rm-tile{
  position:absolute;
  display:flex;align-items:center;justify-content:center;
  border-radius:4px;
  font-family:var(--rm-font-mono);
  font-weight:700;
  font-size:clamp(15px,3.6vw,26px);
  transition:left .13s ease,top .13s ease;
}
.rm-tile--pop{animation:rm-pop .16s ease-out}
@keyframes rm-pop{
  from{transform:scale(.75);opacity:.4}
  to{transform:scale(1);opacity:1}
}

.rm-grid.rm-no-anim .rm-tile{transition:none}

.rm-overlay{
  position:absolute;inset:0;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;
  background:rgba(10,7,18,.9);
  backdrop-filter:blur(3px);
  border-radius:var(--rm-radius);
  text-align:center;
  padding:20px;
  overflow-y:auto;
}
.rm-overlay__title{
  font-family:var(--rm-font-display);
  font-size:clamp(18px,2.6vw,24px);
  color:var(--rm-text);
  margin:0;
}
.rm-overlay__actions{display:flex;gap:14px;flex-wrap:wrap;justify-content:center}

/* ---------- leaderboard ---------- */

.rm-side{
  min-height:0;
  overflow-y:auto;
  padding-top:2px;
}
.rm-side__header{
  display:flex;align-items:flex-start;justify-content:space-between;gap:12px;
}
.rm-side__title{
  font-family:var(--rm-font-display);
  font-size:19px;
  margin:0 0 12px;
  color:var(--rm-text);
}
.rm-side__close{
  display:none; /* only meaningful once the sidebar becomes a mobile drawer */
  background:none;border:0;
  color:var(--rm-text-faint);
  font-size:24px;line-height:1;
  cursor:pointer;padding:2px 4px;
}
.rm-side__close:hover{color:var(--rm-arcane-hot)}

.rm-hud__leaderboard-btn{display:none} /* shown only in the mobile drawer layout below */

.leaderboard{
  background:var(--rm-panel);
  border:1px solid var(--rm-line);
  border-radius:var(--rm-radius);
  padding:4px 20px;
}
.leaderboard__row{
  display:flex;align-items:center;gap:14px;
  padding:10px 0;
  border-top:1px solid var(--rm-line);
  font-family:var(--rm-font-mono);
  font-size:13px;
}
.leaderboard__row:first-child{border-top:none}
.leaderboard__rank{
  color:var(--rm-arcane-hot);
  width:20px;flex:0 0 20px;
}
.leaderboard__name{
  letter-spacing:.12em;
  color:var(--rm-text);
  flex:1;
}
.leaderboard__score{color:var(--rm-text-dim)}
.leaderboard__empty{
  color:var(--rm-text-faint);
  font-family:var(--rm-font-body);
  font-style:italic;
  font-size:14px;
  padding:16px 0;
}

.score-entry{
  background:var(--rm-panel-2);
  border:1px solid var(--rm-line);
  border-left:2px solid var(--rm-arcane);
  border-radius:var(--rm-radius);
  padding:22px 20px;
  margin-top:4px;
  max-width:340px;
}
.score-entry p{margin:0 0 12px;color:var(--rm-text-dim);font-size:14px;font-style:italic}
.score-entry__row{display:flex;flex-wrap:wrap;gap:12px;align-items:center}
.score-entry input{
  font-family:var(--rm-font-mono);
  font-size:19px;font-weight:700;
  letter-spacing:.3em;
  text-transform:uppercase;
  text-align:center;
  width:112px;
  padding:11px 8px;
  background:var(--rm-bg-2);
  border:1px solid var(--rm-line-strong);
  border-radius:4px;
  color:var(--rm-text);
}
.score-entry input:focus{outline:2px solid var(--rm-arcane);outline-offset:2px}

/* ---------- footer ---------- */

.rm-footer{
  flex:0 0 auto;
  display:flex;justify-content:space-between;align-items:center;gap:16px;flex-wrap:wrap;
  max-width:1040px;width:100%;margin:0 auto;
  padding:10px 24px 14px;
  font-family:var(--rm-font-mono);
  font-size:11px;letter-spacing:.06em;
  color:var(--rm-text-faint);
}
.rm-footer a{transition:color .3s ease}
.rm-footer a:hover{color:var(--rm-arcane-hot)}

/* ---------- how-to-play modal (shared component, skinned per game) ---------- */

.htp-overlay{
  position:fixed;inset:0;z-index:200;
  display:none;align-items:center;justify-content:center;
  padding:24px;
  background:rgba(10,7,18,.82);
  backdrop-filter:blur(3px);
}
.htp-panel{
  background:var(--rm-panel);
  border:1px solid var(--rm-line-strong);
  border-radius:var(--rm-radius);
  max-width:440px;width:100%;
  max-height:min(600px,90vh);
  overflow-y:auto;
  padding:26px 24px;
  box-shadow:0 24px 60px -20px rgba(0,0,0,.7);
}
.htp-header{
  display:flex;align-items:flex-start;justify-content:space-between;gap:16px;
  margin-bottom:16px;
}
.htp-title{
  font-family:var(--rm-font-display);
  font-size:21px;margin:0;color:var(--rm-text);
}
.htp-close{
  background:none;border:0;
  color:var(--rm-text-faint);
  font-size:22px;line-height:1;
  cursor:pointer;padding:2px 4px;
}
.htp-close:hover{color:var(--rm-arcane-hot)}
.htp-section{margin-bottom:16px}
.htp-section:last-child{margin-bottom:0}
.htp-heading{
  font-family:var(--rm-font-mono);
  font-size:10px;letter-spacing:.2em;text-transform:uppercase;
  color:var(--rm-arcane-hot);
  margin:0 0 6px;
}
.htp-text{margin:0;color:var(--rm-text-dim);font-size:14px}

/* ---------- responsive ---------- */

@media (max-width:900px){
  /* No fallback scrolling: the leaderboard becomes an on-demand drawer
     instead of a stacked sidebar — the way native mobile games keep
     secondary panels off the main screen — so the board still fits one
     viewport without needing more vertical space than a phone has. */
  .rm-layout{grid-template-columns:1fr}
  .rm-play{height:100%}

  .rm-hud__leaderboard-btn{display:inline-flex}

  .rm-footer{display:none} /* the brandbar's "All games" link already covers this */

  .rm-side{
    position:fixed;inset:0;z-index:150;
    display:none;
    flex-direction:column;
    gap:16px;
    background:rgba(10,7,18,.96);
    backdrop-filter:blur(4px);
    padding:20px 20px calc(20px + env(safe-area-inset-bottom));
    overflow-y:auto;
  }
  .rm-side.is-open{display:flex}
  .rm-side__close{display:block}
}
@media (max-width:520px){
  .rm-brandbar{padding:12px 16px}
  .rm-brandbar__brand span{display:none} /* logo alone reads fine at this width */
  .rm-main{padding:4px 16px 10px}
  .rm-heading{margin-bottom:8px}
  .rm-hud{gap:6px}
  .rm-score{padding:6px 12px;min-width:68px}
  .btn{padding:8px 14px;font-size:10px}
}
