/* shared/tp-layout.css
 * Shared page-chrome for the redesigned practice/quiz/guide pages.
 * Provides the custom header, 2-column layout grid, and every sidebar
 * card (account variants, primary nav, Word Practice CTA, scripts
 * switcher, completion, share, sign-out).
 *
 * Inject the markup with shared/tp-layout.js; page-specific styles live in
 * each page's inline <style>.
 */

:root { --kana: 'Noto Sans JP', sans-serif; }

/* ── Custom header (replaces shared/nav) ── */
.tp-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.tp-header-top {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px 10px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.tp-brand {
  text-decoration: none;
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.1;
}
.tp-brand-title {
  font-family: 'Noto Sans Mono', var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.tp-brand-flag { margin-left: 4px; font-size: 15px; }
.tp-brand-sub {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-3);
}
.tp-header-spacer { flex: 1; }
.tp-script-switch { display: flex; gap: 4px; }
.tp-script-btn {
  font-size: 12px;
  font-family: var(--mono);
  padding: 4px 11px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--text-2);
  text-decoration: none;
  background: transparent;
  transition: all 0.12s;
}
.tp-script-btn:hover { border-color: var(--border-md); color: var(--text); }
.tp-script-btn.active { border-color: var(--accent); background: var(--surface); color: var(--text); font-weight: 500; }

/* Mobile pull-down replaces the three script buttons on narrow screens. */
.tp-script-select { display: none; }

/* Sidebar primary nav (Practice / Quiz / Guide) — inherits sb-card
   padding (14px 14px 16px) so it matches every other sidebar card. */
.sb-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r);
  font-size: 13px;
  color: var(--text-2);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.sb-nav-item:hover { background: var(--bg); color: var(--text); }
.sb-nav-item.active {
  background: var(--accent);
  color: var(--accent-inv);
  font-weight: 500;
}
.sb-nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 13px;
  opacity: 0.7;
}
.sb-nav-item.active .sb-nav-icon { opacity: 1; }

/* Mobile-only header nav — hidden on desktop; revealed at ≤840px alongside
   the sidebar nav being hidden. Styled to match shared/nav's tab bar. */
.tp-header-nav { display: none; }
.tp-header-nav-btn {
  flex: 1;
  padding: 9px 0;
  text-align: center;
  border-right: 1px solid var(--border);
  font-size: 13px;
  background: transparent;
  color: var(--text-2);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  letter-spacing: 0.02em;
}
.tp-header-nav-btn:last-child { border-right: none; }
.tp-header-nav-btn:hover { color: var(--text); background: var(--bg); }
.tp-header-nav-btn.active {
  color: var(--text);
  font-weight: 500;
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* ── Page wrapper ── */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 24px 56px; }

/* ── 2-column layout: sidebar + main ── */
.tp-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 22px;
  align-items: start;
}

.tp-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 16px;
  align-self: start;
  min-width: 0;
}
.tp-main { min-width: 0; }

/* Hide the fixed left-edge share rail from shared/footer.js. */
.share-sidebar { display: none !important; }

/* Sidebar share card. */
.sb-share-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.sb-share-row a {
  flex: 1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--text-3);
  text-decoration: none;
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
  transition: color 0.15s;
}
.sb-share-row a:hover { color: var(--text); }
.sb-share-row svg { width: 18px; height: 18px; fill: currentColor; }

/* Sidebar cards */
.sb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 14px 14px 16px;
}
.sb-card-label {
  font-size: 9px;
  font-family: var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
}

/* ── Account variants ── */
.sb-account { display: none; }
body.state-anon   .sb-account[data-show-state="anon"]   { display: block; }
body.state-signed .sb-account[data-show-state="signed"] { display: block; }
body.state-free   .sb-account[data-show-state="free"]   { display: block; }
body.state-pro    .sb-account[data-show-state="pro"]    { display: block; }

.sb-account-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sb-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-2);
  text-transform: uppercase;
  flex-shrink: 0;
}
.sb-avatar.pro {
  background: linear-gradient(135deg, #1c1b18, #4a4845);
  color: #fff;
  border-color: var(--accent);
}
.sb-avatar.placeholder { font-family: var(--kana); font-size: 16px; color: var(--text-3); }
.sb-account-name { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.2; }
.sb-account-plan { font-size: 11px; color: var(--text-2); font-family: var(--mono); margin-top: 2px; }

.sb-actions { display: flex; flex-direction: column; gap: 6px; }

.sb-account-benefits {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sb-account-benefits li {
  position: relative;
  padding-left: 16px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
}
.sb-account-benefits li::before {
  content: '✓';
  position: absolute;
  left: 0;
  top: 0;
  color: var(--green);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}

/* Per-script completion rate. */
.sb-completion { display: flex; flex-direction: column; gap: 10px; }
.sb-completion-row { display: flex; flex-direction: column; gap: 4px; }
.sb-completion-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px;
}
.sb-completion-label { font-size: 12px; color: var(--text-2); }
.sb-completion-pct {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}
.sb-completion-bar {
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.sb-completion-bar > div {
  height: 100%;
  background: var(--text);
  border-radius: 99px;
}

/* ── Scripts switcher (cross-script dashboard) ── */
.sb-script {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px;
  border-radius: var(--r);
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s;
}
.sb-script:hover { background: var(--bg); }
.sb-script.active { background: var(--bg); }
.sb-script.active .sb-script-name { font-weight: 600; }
.sb-script-glyph {
  font-family: var(--kana);
  font-size: 17px;
  width: 22px;
  text-align: center;
  color: var(--text);
  flex-shrink: 0;
}
.sb-script-info { flex: 1; min-width: 0; }
.sb-script-name { font-size: 13px; color: var(--text); }
.sb-script-pct { font-size: 10px; font-family: var(--mono); color: var(--text-3); margin-top: 1px; }
.sb-script-pct.unknown { color: var(--text-3); }
body.state-anon .sb-script-pct { color: var(--text-3); }

/* ── Sign out (signed-in only) ── */
.sb-link {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  text-decoration: none;
  padding: 4px 0;
}
.sb-link:hover { color: var(--text); }
body.state-anon .sb-hide-when-anon { display: none; }

/* ── Pills + buttons ── */
.pro-pill {
  display: inline-block;
  font-size: 9px;
  font-family: var(--mono);
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-inv);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: middle;
  margin-left: 4px;
}
.btn {
  display: inline-block;
  padding: 7px 12px;
  border-radius: var(--r);
  font-size: 12px;
  font-family: inherit;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: var(--accent-inv); border-color: var(--accent); }
.btn-primary:hover { opacity: 0.85; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--border-md); }
.btn-block { display: block; width: 100%; }

/* Pro-locked sidebar items */
body.state-anon [data-requires="pro"],
body.state-signed [data-requires="pro"],
body.state-free [data-requires="pro"] {
  opacity: 0.55;
  pointer-events: none;
}
body.state-pro [data-requires="pro"] .pro-pill { display: none; }

/* Sidebar CTA (Word Practice). */
.sb-cta {
  position: relative;
  display: block;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.sb-cta:hover { border-color: var(--border-md); background: var(--surface); }
.sb-cta-text { font-size: 13px; line-height: 1.4; color: var(--text); font-weight: 500; }
.sb-cta-badge {
  position: absolute;
  top: -10px;
  left: -8px;
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 99px;
}
/* Variant colors — driven by JS from auth state.
   new   → anon:    red bg, white text (sign-up prompt)
   light → free:    amber bg, dark text (free tier of Word Practice)
   pro   → paid:    green bg, white text (pro tier only) */
.sb-cta-badge.new   { background: var(--red);   color: #fff; }
.sb-cta-badge.light { background: #f5cf42;      color: #4a3400; }
.sb-cta-badge.pro   { background: var(--green); color: #fff; }

/* ────────── Responsive (chrome only) ────────── */
@media (max-width: 840px) {
  .tp-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .tp-sidebar { position: static; order: 2; }
  .tp-main    { order: 1; }
  /* Promote Practice/Quiz/Guide out of the sidebar and up under the
     header so it stays reachable without scrolling past the content. */
  .tp-header-nav { display: flex; border-top: 1px solid var(--border); }
  .sb-card.sb-nav { display: none; }
}

@media (max-width: 580px) {
  .tp-header-top { padding: 12px 14px 10px; gap: 10px; flex-wrap: wrap; }
  .tp-brand-title { font-size: 15px; }
  .tp-brand-sub { font-size: 11px; }
  .tp-script-switch { display: none; }
  .tp-script-select {
    display: block;
    font-size: 13px;
    font-family: var(--kana);
    padding: 5px 26px 5px 12px;
    border-radius: 99px;
    border: 1px solid var(--accent);
    background-color: var(--bg);
    color: var(--text);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%231c1b18'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
  }

  .page { padding: 16px 14px 64px; }

  .sb-card { padding: 16px; }
  .sb-card-label { font-size: 10px; }
  .sb-nav-item { font-size: 14px; padding: 10px 12px; }
  .sb-account-name { font-size: 14px; }
  .sb-account-plan { font-size: 12px; }
  .sb-account-benefits li { font-size: 13px; }
  .sb-script-name { font-size: 14px; }
  .sb-script-pct { font-size: 11px; }
  .sb-completion-label { font-size: 13px; }
  .sb-completion-pct { font-size: 12px; }
  .sb-cta-text { font-size: 14px; }
  .btn { font-size: 13px; padding: 9px 14px; }
}

@media (max-width: 380px) {
  .page { padding: 14px 10px 60px; }
  .sb-card { padding: 14px; }
}
