/* css/styles.css — mobile & tile text polish */
/* ---------- Tokens ---------- */
:root {
  --bg: #0b0d10;
  --bg-accent: #142034;
  --card: #151922;
  --muted: #b9c3d1;
  --fg: #f7faff;
  --accent: #6aa8ff;
  --good: #60d394;
  --warn: #ffd166;
  --bad: #ef476f;
  --tile: #1d2330;
  --tile-hover: #242b3b;
  --tile-selected: #2e3750;
  --border: #2a3242;
  --shadow: 0 14px 35px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.02);
  --radius-lg: 18px;
  --radius-sm: 12px;
  --backdrop: rgba(0,0,0,.5);
  --glass: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  --grad1: #6aa8ff; --grad2: #a86aff;
}
:root[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-accent: #dfe7fb;
  --card: #ffffff;
  --muted: #5a6676;
  --fg: #12161f;
  --accent: #2a5bff;
  --good: #198754;
  --warn: #d59600;
  --bad: #c92a52;
  --tile: #f0f3fa;
  --tile-hover: #e8eefc;
  --tile-selected: #dfe7fb;
  --border: #d8deea;
  --shadow: 0 14px 30px rgba(0,0,0,.08), inset 0 1px 0 rgba(255,255,255,.8);
  --backdrop: rgba(0,0,0,.35);
  --glass: linear-gradient(180deg, rgba(0,0,0,.04), rgba(0,0,0,.02));
  --grad1: #2a5bff; --grad2: #7e6bff;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter, "Helvetica Neue", Arial, "Noto Sans";
  background: radial-gradient(80rem 60rem at 60% -10%, var(--bg-accent) 12%, var(--bg) 58%);
  color: var(--fg);
  min-height: 100vh;
  min-height: 100dvh;
  display: grid; place-items: start center;
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.app { width: min(980px, 95vw); }

header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 42px; height: 42px; border-radius: 50%; background: linear-gradient(145deg, var(--grad1), var(--grad2)); box-shadow: var(--shadow); border: 1px solid var(--border); flex: 0 0 auto; }
h1 { font-size: clamp(20px, 4.2vw, 24px); margin: 0; letter-spacing: .2px; }
.sub { color: var(--muted); font-size: clamp(12px, 3.3vw, 13px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 68vw; }

.card { background: var(--glass); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: var(--radius-lg); padding: clamp(12px, 3.2vw, 16px); width: 100%; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { background: var(--card); border: 1px solid var(--border); color: var(--fg); border-radius: 12px; padding: clamp(10px, 2.8vw, 12px) clamp(12px, 3.6vw, 14px); cursor: pointer; font-weight: 700; font-size: clamp(12px, 3.4vw, 14px); transition: transform .05s, background .2s, border-color .2s, box-shadow .2s; touch-action: manipulation; }
.btn:hover { transform: translateY(-1px); background: #1a2030; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
:root[data-theme="light"] .btn:hover { background: #eef3ff; }
.btn.primary { background: linear-gradient(180deg, #2a5bff, #1b46d1); border-color: #1b46d1; color: #fff; }
.btn.good { background: linear-gradient(180deg, #1f9e68, #17764f); border-color: #17764f; color: #fff; }
.btn.warn { background: linear-gradient(180deg, #ffc300, #e6a800); border-color: #cc9700; color: #0b0d10; }
.btn.bad  { background: linear-gradient(180deg, #e5386d, #c72757); border-color: #b21f4c; color: #fff; }
.btn:disabled { opacity: .65; cursor: not-allowed; transform: none; }

.statusbar { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; margin-top: 10px; color: var(--muted); font-size: clamp(12px, 3.2vw, 13px); }
.lives span { font-size: clamp(16px, 4vw, 18px); margin-left: 2px; }

.grid { margin-top: 12px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(6px, 2.2vw, 10px); }
.tile {
  user-select: none;
  padding: clamp(10px, 2.8vw, 14px) clamp(8px, 2.6vw, 10px);
  text-align: center;
  border: 1px solid var(--border);
  background: var(--tile);
  border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 800; letter-spacing: .2px;
  min-height: clamp(56px, 14vw, 82px);
  display: grid; place-items: center;
  box-shadow: var(--shadow);
  transition: background .15s, transform .05s, border-color .2s;
  color: var(--fg);
  /* New: keep words on one line, graceful ellipsis */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: keep-all;
  letter-spacing: .02em;
  line-height: 1.15;
}
.tile:hover { background: var(--tile-hover); transform: translateY(-1px); }
.tile.selected { background: var(--tile-selected); border-color: #3a4560; }
:root[data-theme="light"] .tile.selected { border-color: #b5c7ff; }
.tile.solved { background: #0f141d; opacity: .5; cursor: default; }
:root[data-theme="light"] .tile.solved { background: #e3e7f3; opacity: .6; }

.hint { font-size: clamp(12px, 3.2vw, 13px); color: var(--warn); margin-top: 8px; min-height: 18px; }
footer { margin-top: 16px; color: var(--muted); font-size: clamp(11px, 3.1vw, 12px); text-align: center; }
.hidden { display: none !important; }

/* ---------- Share modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: var(--backdrop); display: grid; place-items: center; z-index: 1300; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  width: min(640px, 96vw); box-shadow: var(--shadow);
  padding: 16px; color: var(--fg);
  max-height: 90dvh; overflow: auto;
}
.modal h3 { margin: 0 0 8px; font-size: clamp(16px, 4.5vw, 20px); }
.share-row { display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.socials { display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
#share-img-preview { width: 100%; border-radius: 16px; border: 1px dashed var(--border); background: #0e131c; aspect-ratio: 1200/630; object-fit: cover; }

/* ---------- Centered result popup ---------- */
.result-backdrop { position: fixed; inset: 0; background: var(--backdrop); opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 1200; }
.result-backdrop.show { opacity: 1; pointer-events: auto; }
.toast {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.96);
  background: var(--glass); border: 1px solid var(--border); border-radius: 22px;
  box-shadow: var(--shadow); width: min(520px, 92vw); max-height: 90dvh; overflow: auto;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; backdrop-filter: blur(10px); z-index: 1201; outline: none; overflow: hidden;
}
.toast::before { content: ""; position: absolute; inset: -2px -2px auto -2px; height: 6px; background: linear-gradient(90deg, var(--grad1), var(--grad2)); }
.toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.toast-body { padding: clamp(14px, 3.6vw, 18px); display: grid; gap: 12px; place-items: center; text-align: center; }
.toast-title { font-size: clamp(18px, 5vw, 22px); font-weight: 900; letter-spacing: .3px; }
.rating-badge { display:inline-flex; align-items:center; gap:8px; padding: 8px 14px; border-radius: 999px; font-weight: 800; font-size: clamp(13px, 3.7vw, 14px); background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.04)); border: 1px solid var(--border); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: clamp(10px, 3vw, 12px); display:grid; gap:4px; place-items:center; min-width: 80px; }
.stat .label { color: var(--muted); font-size: clamp(11px, 3.2vw, 12px); }
.stat .value { font-weight: 900; font-size: clamp(16px, 4.6vw, 18px); }
.toast-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }

/* ---------- Tiny phones tweaks ---------- */
@media (max-width: 420px) {
  body { padding: 16px; }
  .sub { max-width: 60vw; }
  .grid { gap: 6px; }
  .tile { font-size: clamp(13px, 3.6vw, 16px); }
  .toolbar { gap: 6px; }
  .statusbar { grid-template-columns: 1fr auto; row-gap: 6px; }
  .statusbar .muted:last-child { grid-column: 1 / -1; justify-self: end; }
}

/* Prefer less motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- Fancy heading & tagline (no markup changes) --- */
:root{
  --h1g1:#a9c3ff; --h1g2:#6aa8ff;        /* dark theme headline gradient */
  --sub-bg: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
  --sub-fg: rgba(255,255,255,.92);
}
:root[data-theme="light"]{
  --h1g1:#1e2a55; --h1g2:#2a5bff;        /* light theme: deeper for contrast */
  --sub-bg: linear-gradient(180deg, rgba(0,0,0,.04), rgba(0,0,0,.02));
  --sub-fg: rgba(0,0,0,.78);
}

/* Headline: gradient ink + soft accent underline */
header .title h1{
  position: relative;
  margin: 0;
  font-weight: 900;
  letter-spacing: .2px;
  text-wrap: balance;
  font-size: clamp(22px, 5.4vw, 36px);
  background: linear-gradient(180deg, var(--h1g1), var(--h1g2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 18px rgba(106,168,255,.22));
}
header .title h1::after{
  content:"";
  display:block;
  height: 6px;
  width: 56%;
  margin-top: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--grad1), var(--grad2));
  opacity:.85;
}

/* Tagline: frosted pill with subtle border */
header .title .sub{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--sub-bg);
  border: 1px solid var(--border);
  color: var(--sub-fg);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

/* Logo: glossy orb + faint ring */
.logo{
  position: relative;
  background: radial-gradient(120% 120% at 30% 30%, #7bb0ff 0%, #6a8cff 55%, #6aa8ff 100%);
  outline: 2px solid rgba(255,255,255,.12);
}
.logo::after{
  content:"";
  position:absolute; inset:-3px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, var(--grad1), var(--grad2), var(--grad1));
  opacity:.25;
  z-index:-1;
}

.howto{
  margin: 6px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--glass);
  color: var(--fg);
  font-size: clamp(12px, 3.2vw, 14px);
  box-shadow: var(--shadow);
}
.howto strong{ font-weight: 800; margin-right: 6px; }
.howto em{ font-style: normal; font-weight: 800; }
:root[data-theme="light"] .howto{ background: linear-gradient(180deg, rgba(0,0,0,.04), rgba(0,0,0,.02)); }


/* --- Responsive spacing for heading + how-to --- */

/* Header gets a bit tighter on phones, roomier on desktop */
header { margin-bottom: clamp(8px, 2vw, 16px); }

/* How-to pill: compact on mobile, comfy on larger screens */
.howto{
  margin-top: clamp(4px, 1vw, 8px);
  margin-bottom: clamp(10px, 2.4vw, 20px);
  padding: clamp(8px, 2vw, 12px) clamp(10px, 2.4vw, 16px);
  line-height: 1.25;
}

/* Ensure the main card sits snugly after the how-to */
.card { margin-top: 0; }

/* Tiny phones: extra-tight layout */
@media (max-width: 420px){
  header { margin-bottom: 8px; }
  .howto { margin: 6px 0 12px; padding: 8px 10px; }
}

/* Wider screens: a touch more breathing room */
@media (min-width: 1024px){
  header { margin-bottom: 18px; }
  .howto { margin-bottom: 20px; }
}

/* --- Center on mobile & prevent sideways scroll --- */
html, body { width: 100%; overflow-x: hidden; }

body{
  /* keep your other body styles; these override layout/padding */
  display: block;  /* was: grid */
  padding-inline: clamp(12px, 3.5vw, 24px);
  padding-block: 24px calc(24px + env(safe-area-inset-bottom, 0px));
}

.app{
  max-width: 980px;
  width: 100%;
  margin-inline: auto;  /* centers the site */
}

/* Make tiles use flex so the inner label can ellipsize */
.tile{
  display:flex;                /* was: grid */
  align-items:center;
  justify-content:center;
}

/* The label inside each tile: one line, graceful ellipsis */
.tile-label{
  display:block;
  width:100%;
  max-width:100%;
  padding-inline:2px;          /* tiny breathing room */
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  word-break:keep-all;
}

/* --- Tile label: readable on mobile, no ellipsis cut-offs --- */
.tile{
  display:flex;              /* center content so wrapped lines look neat */
  align-items:center;
  justify-content:center;
}

.tile-label{
  display:block;
  width:100%;
  max-width:100%;
  padding-inline:2px;
  white-space:normal;        /* allow wrap if needed */
  overflow:visible;          /* no clipping */
  text-overflow:clip;        /* no … */
  word-break:break-word;     /* break long uppercase words cleanly */
  line-height:1.1;
}
/* One-line tiles: center + no wrap */
.tile{
  display:flex;
  align-items:center;
  justify-content:center;
}

.tile-label{
  display:block;
  width:100%;
  max-width:100%;
  padding-inline:2px;
  white-space:nowrap;     /* keep to a single line */
  overflow:hidden;        /* hide any extra while we shrink */
  text-overflow:clip;     /* no ellipsis */
  word-break:keep-all;    /* don’t split words in the middle */
  line-height:1.05;
}

/* --- Fix subtitle truncation on phones --- */
@media (max-width: 600px){
  header .title { align-items: flex-start; min-width: 0; } /* let text shrink/wrap */
  header .title .sub{
    display: block;        /* was inline-flex */
    white-space: normal;   /* allow wrapping */
    overflow: visible;     /* don't clip */
    text-overflow: clip;   /* no ellipsis */
    max-width: 100%;       /* use available width */
    line-height: 1.25;
    margin-top: 6px;
  }
}
/* --- Mobile: make the game card full-bleed (edge-to-edge) --- */
@media (max-width: 600px){
  header, .howto, .card{
    /* stretch to the screen edges, respecting our centered layout */
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);

    /* tighten padding so tiles get more width/height */
    padding: 10px;

    /* keep the nice rounded look */
    border-radius: 16px;
  }

  /* give tiles a bit more room too */
  .grid{ gap: 6px; }
  .tile{ padding: 10px 8px; min-height: clamp(54px, 14vw, 80px); }
}
/* --- Mobile: align subtitle under the H1 (no stretch) --- */
@media (max-width: 600px){
  header .title{ align-items: flex-start; }

  /* make the pill size to its text, allow wrapping, and align with the H1 */
  header .title .sub{
    display: inline-block;      /* shrink to content instead of full row */
    width: -moz-fit-content;
    width: fit-content;
    max-width: 100%;            /* still wrap when needed */
    white-space: normal;        /* allow 2 lines */
    overflow: visible;          /* no clipping */
    text-overflow: clip;
    margin-left: 0;             /* same left edge as the H1 */
    padding: 6px 10px;          /* compact pill on phones */
    line-height: 1.25;
  }
}
/* --- Mobile: subtitle left-aligned with H1 --- */
@media (max-width: 600px){
  /* make the text column start from the same left edge as the H1 */
  header .title{ align-items: flex-start; }
  header .title > div{
    display: flex;
    flex-direction: column;
    align-items: flex-start;   /* anchor left */
    min-width: 0;              /* allow wrapping */
  }

  /* subtitle pill: size to content, not full width */
  header .title .sub{
    display: inline-block;
    width: auto;               /* don’t stretch */
    max-width: 100%;           /* wrap if needed */
    white-space: normal;       /* allow 2 lines */
    overflow: visible;         /* no clipping */
    text-overflow: clip;
    margin-left: 0;            /* same left edge as H1 */
    padding: 6px 10px;         /* compact on phones */
    line-height: 1.25;
  }
}
