/* The Elements -- an interactive periodic-table game for primary-school
   children. Dark "science lab" theme so the color-coded element cells pop.
   Big tap targets, readable type, reduced-motion support. */

:root {
  --bg:      #0e1320;   /* deep navy lab background */
  --panel:   #19223a;
  --panel-2: #222d49;
  --ink:     #eaf0fb;
  --muted:   #97a3bd;
  --line:    #2c3958;
  --accent:  #4cc9f0;   /* cyan */
  --accent-2:#ffd166;   /* amber */
  --good:    #06d6a0;
  --bad:     #ff6b6b;
  --cell-ink:#16203a;   /* dark text used on the bright element cells */
  --shadow:  0 8px 24px rgba(0, 0, 0, 0.35);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "Segoe UI Rounded", "SF Pro Rounded", "Segoe UI",
               system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body { display: flex; justify-content: center; }

.app {
  position: relative;
  width: 100%;
  max-width: 1100px;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

/* ---- Screen switching ---- */
.screen { display: none; flex: 1; flex-direction: column; padding: 16px; }
.screen.is-active { display: flex; }
[hidden] { display: none !important; }

/* ====================== HOME ====================== */
.home { align-items: center; }
.home-head { text-align: center; margin: 22px 0 18px; }
.home-head h1 { font-size: clamp(28px, 8vw, 44px); font-weight: 800; letter-spacing: 0.3px; }
.tagline { color: var(--muted); margin-top: 8px; font-size: clamp(14px, 4vw, 18px); }

.home-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  width: 100%;
  max-width: 560px;
  margin: 8px 0 22px;
}
.big-btn {
  flex: 1 1 220px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 22px;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--ink);
  font-family: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.big-btn:hover { transform: translateY(-3px); }
.big-btn:active { transform: scale(0.98); }
.big-btn.explore:hover { border-color: var(--accent); }
.big-btn.quiz:hover { border-color: var(--accent-2); }
.big-emoji { font-size: 40px; }
.big-label { font-size: clamp(20px, 5vw, 26px); font-weight: 800; }
.big-sub { font-size: 13px; color: var(--muted); text-align: center; }

.home-legend { max-width: 560px; }
.home-foot { display: flex; gap: 18px; margin-top: 18px; align-items: center; }

/* ====================== TOP BAR ====================== */
.play-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.icon-btn {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
  min-height: 44px;
}
.icon-btn:hover { border-color: var(--accent); }
.bar-title { font-size: 17px; font-weight: 800; color: var(--ink); text-align: center; flex: 1; }

/* ====================== PERIODIC TABLE ====================== */
.scroll-hint { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 8px; }
/* The table fits without scrolling once there is enough width, so hide the
   sideways-scroll hint there. */
@media (min-width: 680px) { .scroll-hint .swipe { display: none; } }

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}
.ptable {
  /* Cell size grows to fill the available width (capped at 56px) so the whole
     table fits without horizontal scroll on desktop, and shrinks to a 34px
     floor on phones, where the parent .table-scroll then scrolls sideways.
     The width budget is min(viewport, app max-width) minus padding, split over
     18 columns less the 3px gaps. */
  --cell: clamp(34px, calc((min(100vw, 1100px) - 44px) / 18 - 3px), 56px);
  display: grid;
  grid-template-columns: repeat(18, var(--cell));
  grid-template-rows: repeat(7, var(--cell)) 14px repeat(2, var(--cell));
  gap: 3px;
  width: max-content;
  margin: 0 auto;
}
.cell {
  border-radius: 7px;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}
.cell.el {
  border: none;
  color: var(--cell-ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px 1px;
  line-height: 1;
  transition: transform 0.08s ease, box-shadow 0.12s ease, outline 0.1s ease;
}
.cell.el:hover { transform: scale(1.12); z-index: 5; box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
.cell.el:active { transform: scale(1.02); }
.cell.el:focus-visible { outline: 3px solid #fff; z-index: 6; }
.cell .num { font-size: 9px; font-weight: 700; opacity: 0.85; align-self: flex-start; margin-left: 2px; }
.cell .sym { font-size: clamp(13px, 1.8vw, 18px); font-weight: 800; }
.cell .mini-name { display: none; }
.cell.marker {
  background: var(--panel-2);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
}

/* ====================== LEGEND ====================== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  margin: 14px auto 4px;
  width: 100%;
  max-width: 900px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-item .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }

/* ====================== ELEMENT DETAIL / SHEETS ====================== */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(6, 10, 20, 0.7);
  align-items: center;
  justify-content: center;
  padding: 18px;
  backdrop-filter: blur(2px);
}
.detail-card, .sheet-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  position: relative;
  max-height: 92vh;
  overflow-y: auto;
}
.close-x {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--panel-2);
  border: none;
  color: var(--ink);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}
.close-x:hover { background: var(--line); }

.detail-card { border-top: 6px solid var(--accent); }
.d-top { display: flex; gap: 16px; align-items: center; margin: 4px 0 16px; }
.d-sym {
  width: 84px; height: 84px;
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 800;
  color: var(--cell-ink);
  flex: none;
}
.d-head { display: flex; flex-direction: column; gap: 4px; }
.d-num-label { font-size: 12px; color: var(--muted); }
.d-num { font-weight: 800; color: var(--ink); font-size: 14px; }
.d-name { font-size: clamp(22px, 6vw, 30px); font-weight: 800; }
.d-cat {
  align-self: flex-start;
  font-size: 12px; font-weight: 800;
  color: var(--cell-ink);
  border-radius: 10px;
  padding: 3px 10px;
}
.d-stats { display: flex; gap: 10px; margin-bottom: 16px; }
.stat {
  flex: 1;
  background: var(--panel-2);
  border-radius: 14px;
  padding: 10px 8px;
  text-align: center;
  display: flex; flex-direction: column; gap: 3px;
}
.stat-label { font-size: 11px; color: var(--muted); }
.stat-val { font-size: 16px; font-weight: 800; }
.d-fact { font-size: clamp(14px, 4vw, 16px); line-height: 1.55; color: var(--ink); margin-bottom: 14px; }
.d-examples-wrap { margin-bottom: 18px; }
.d-examples-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.d-examples-list { display: flex; flex-wrap: wrap; gap: 6px; }
.d-example-chip {
  font-size: 13px; font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 12px;
  color: var(--ink);
}
.d-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.d-btns .round-btn { flex: 1 1 140px; }

/* ====================== QUIZ SETUP ====================== */
.pick-label {
  font-size: clamp(15px, 4.4vw, 18px);
  font-weight: 700;
  color: var(--ink);
  margin: 10px 0 14px;
  text-align: center;
}
.level-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
}
.level-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--ink);
  font-family: inherit;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.level-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.level-card:active { transform: scale(0.98); }
.lvl-emoji { font-size: 34px; }
.lvl-name { font-size: clamp(18px, 5vw, 22px); font-weight: 800; }
.lvl-sub { font-size: 13px; color: var(--muted); }

/* ====================== QUIZ ====================== */
.q-bar { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; margin: 4px 0 6px; }
.q-bar-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.3s ease; }
.q-progress { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 12px; }

.q-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 20px;
  padding: 22px 18px;
  text-align: center;
  margin: 0 auto 16px;
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}
.q-prompt { font-size: clamp(17px, 4.8vw, 22px); font-weight: 800; line-height: 1.4; }
.q-sub { font-size: 13px; color: var(--muted); }

.q-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}
.choice {
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  font-family: inherit;
  font-size: clamp(16px, 4.6vw, 20px);
  font-weight: 800;
  padding: 18px 12px;
  min-height: 64px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:active:not(:disabled) { transform: scale(0.97); }
.choice:disabled { cursor: default; }
.choice.is-right { background: var(--good); border-color: var(--good); color: #06281f; }
.choice.is-wrong { background: var(--bad); border-color: var(--bad); color: #2a0a0a; }

.q-feedback { text-align: center; font-size: 16px; font-weight: 700; min-height: 24px; margin: 14px 0 6px; }
.q-feedback.good { color: var(--good); }
.q-feedback.bad { color: var(--bad); }
.q-next { margin: 0 auto; min-width: 200px; }

/* ====================== RESULT ====================== */
.result { align-items: center; justify-content: center; text-align: center; gap: 6px; }
.result-title { font-size: clamp(22px, 6vw, 30px); font-weight: 800; }
.result-stars { font-size: 48px; letter-spacing: 6px; margin: 6px 0; }
.result-score { font-size: clamp(28px, 8vw, 40px); font-weight: 800; color: var(--accent); }
.result-msg { font-size: clamp(15px, 4.4vw, 18px); color: var(--ink); max-width: 30ch; line-height: 1.5; }
.result-level { font-size: 13px; color: var(--muted); }
.result-best { font-size: 14px; color: var(--accent-2); font-weight: 700; }
.result-btns { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; width: 100%; max-width: 320px; }

/* ====================== BUTTONS ====================== */
.round-btn {
  font-family: inherit;
  font-weight: 800;
  font-size: clamp(15px, 4.4vw, 18px);
  border-radius: 16px;
  padding: 14px 22px;
  min-height: 54px;
  cursor: pointer;
  border: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.round-btn:active { transform: scale(0.97); }
.round-btn.soft { background: var(--panel-2); border-color: var(--line); color: var(--ink); }
.round-btn.soft:hover { border-color: var(--accent); }
.round-btn.go { background: var(--accent); color: #06222b; }
.round-btn.go:hover { background: #6fd6f5; }

.text-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-btn:hover { color: var(--ink); }
.text-btn.home { display: inline-block; text-decoration: none; }
.setup .text-btn.home { margin: 18px auto 0; }

/* ====================== SETTINGS SHEET ====================== */
.sheet-card h2 { font-size: 22px; margin-bottom: 6px; }
.sheet-intro, .sheet-note { font-size: 14px; color: var(--muted); line-height: 1.55; margin-bottom: 12px; }
.sheet-intro strong, .sheet-note strong { color: var(--ink); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 16px; margin-bottom: 12px; }
.row.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.about { font-size: 14px; color: var(--muted); line-height: 1.55; margin-bottom: 14px; }
.about summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.about p { margin-top: 8px; }

/* ====================== OBJECT SEARCH ====================== */
.big-btn.search-obj:hover { border-color: #a78bfa; }

.obj-search-screen { gap: 16px; }
.obj-hint { font-size: clamp(14px, 4vw, 16px); color: var(--muted); text-align: center; }

.obj-input-wrap { width: 100%; max-width: 520px; align-self: center; }
.obj-input {
  width: 100%;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 18px;
  font-size: clamp(16px, 4.5vw, 18px);
  color: var(--ink);
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
}
.obj-input:focus { border-color: var(--accent); }
.obj-input::-webkit-search-cancel-button { cursor: pointer; }

.obj-popular { width: 100%; max-width: 520px; align-self: center; }
.obj-popular-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.obj-popular-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.obj-pop-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px; font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.1s ease;
}
.obj-pop-chip:hover { border-color: var(--accent); }

.obj-suggestions { width: 100%; max-width: 520px; align-self: center; display: flex; flex-direction: column; gap: 6px; }
.obj-sug-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px; font-weight: 600;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.obj-sug-btn:hover { background: var(--panel-2); border-color: var(--accent); }

.obj-empty { font-size: 15px; color: var(--muted); text-align: center; line-height: 1.6; max-width: 420px; align-self: center; }

.obj-result { width: 100%; }
.obj-result-label { font-size: 16px; font-weight: 700; color: var(--muted); margin-bottom: 16px; }
.obj-result-label strong { color: var(--ink); }

.obj-elem-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.obj-elem-tile {
  width: 84px; height: 84px;
  border: none; border-radius: 14px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s ease;
}
.obj-elem-tile:hover, .obj-elem-tile:focus { transform: scale(1.07); outline: 2px solid rgba(255,255,255,0.4); }
.obj-tile-sym { font-size: 28px; font-weight: 800; color: var(--cell-ink); }
.obj-tile-name { font-size: 10px; font-weight: 700; color: var(--cell-ink); }
.obj-tap-hint { font-size: 12px; color: var(--muted); margin-top: 14px; }

/* ====================== FOOTER ====================== */
.foot { text-align: center; font-size: 10px; color: var(--muted); opacity: 0.5; padding: 8px; }

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