:root {
  --carolina: #4B9CD3;
  --carolina-dark: #3d87bd;
  --carolina-soft: #e8f2f9;
  --nu-purple: #4E2A84;
  --gold: #FFC83D;
  --surface: #ffffff;
  --surface-2: #f1f4f7;
  --text: #1a2733;
  --muted: #788694;
  --border: #e2e8ee;
  --danger: #e5484d;
  --danger-press: #cf3b40;
  --ok: #2f8f5b;
  --rounded: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Quicksand", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body { background: var(--carolina); }
#app { min-height: 100vh; }

.view { display: none; }
.view.active { display: flex; }

/* ---------- AUTH (login / register) ---------- */
.view.auth { min-height: 100vh; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: 0;                 /* square corners */
  border: 1px solid var(--carolina-dark);
  padding: 30px 26px;
  box-shadow: 0 14px 40px rgba(0,0,0,.18);
}
h1 { margin: 0 0 4px; font-size: 24px; }
.muted { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .opt { color: var(--muted); font-weight: 400; font-style: normal; }
.field input {
  width: 100%; padding: 12px 13px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 0; background: #fbfdff;
  outline: none; transition: border .15s ease;
}
.field input:focus { border-color: var(--carolina); }
.hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }

.rules { list-style: none; margin: -4px 0 16px; padding: 10px 12px; background: var(--surface-2); font-size: 12.5px; }
.rules li { position: relative; padding-left: 22px; margin: 5px 0; color: var(--muted); transition: color .15s ease; }
.rules li::before { content: "\25CB"; position: absolute; left: 4px; top: 0; }
.rules li.ok { color: var(--ok); }
.rules li.ok::before { content: "\2713"; color: var(--ok); font-weight: 700; }

.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }

.btn {
  appearance: none; border: none; width: 100%; padding: 14px;
  font-size: 16px; font-weight: 700; border-radius: 0;
  background: var(--carolina); color: #fff; cursor: pointer;
  transition: background .15s ease, transform .05s ease, opacity .15s ease;
}
.btn:active { transform: scale(.99); background: var(--carolina-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn--code { width: auto; white-space: nowrap; padding: 0 16px; font-size: 14px; background: var(--nu-purple); }

.message { font-size: 13px; padding: 10px 12px; margin: 4px 0 14px; border-radius: 0; }
.message.error   { background: #fdecea; color: #c0392b; }
.message.success { background: #e8f7ee; color: var(--ok); }

.switch { text-align: center; margin: 18px 0 0; font-size: 14px; color: var(--muted); }
.switch a { color: var(--carolina-dark); font-weight: 700; text-decoration: none; margin-left: 4px; }

/* ---------- MAIN app shell (responsive) ---------- */
.view.app {
  flex-direction: column; width: 100%; max-width: 480px; margin: 0 auto;
  min-height: 100vh; background: #fbfcfe;
  border-left: 1px solid var(--carolina-dark); border-right: 1px solid var(--carolina-dark);
}

.topbar {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 52px;
  background: var(--carolina); color: #fff;
  padding: calc(10px + var(--safe-top)) 14px 11px;
  box-shadow: 0 2px 10px rgba(59,135,189,.35);
}
.topbar-title {
  font-family: var(--rounded);
  font-weight: 600; font-size: 20px; letter-spacing: .5px; color: #fff;
}

.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px 16px 28px; }

.panel { display: none; animation: fade .22s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-title { margin: 4px 0 4px; font-size: 23px; }
.page-sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }

/* ----- Learn ----- */
.hero-card {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, var(--carolina), var(--carolina-dark));
  color: #fff; border-radius: 18px; padding: 18px; margin-bottom: 24px;
  box-shadow: 0 10px 24px rgba(59,135,189,.3);
}
.hero-text { flex: 1; }
.hero-kicker { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; opacity: .85; }
.hero-text h3 { margin: 4px 0 10px; font-size: 18px; }
.progress { height: 7px; background: rgba(255,255,255,.3); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.progress span { display: block; height: 100%; background: #fff; border-radius: 999px; }
.hero-text small { opacity: .9; font-size: 12px; }
.hero-btn {
  appearance: none; border: none; cursor: pointer;
  background: #fff; color: var(--carolina-dark); font-weight: 700; font-size: 14px;
  padding: 11px 16px; border-radius: 12px; white-space: nowrap;
}
.hero-btn:active { transform: scale(.97); }

.section-label { margin: 0 0 10px; font-size: 13px; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); }

.lesson-row {
  width: 100%; appearance: none; cursor: pointer;
  display: flex; align-items: center; gap: 13px;
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 14px 16px; margin-bottom: 11px; text-align: left;
  transition: transform .05s ease, box-shadow .15s ease;
}
.lesson-row:active { transform: scale(.99); }
.lesson-row:hover { box-shadow: 0 6px 16px rgba(0,0,0,.06); }
.lesson-ico {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--carolina-soft); color: var(--carolina-dark);
  border-radius: 12px; font-size: 20px;
}
.lesson-body { flex: 1; display: flex; flex-direction: column; }
.lesson-body b { font-size: 15px; }
.lesson-body small { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.lesson-state { font-size: 16px; }
.lesson-state.done { color: var(--ok); }
.lesson-state.lock { filter: grayscale(1); opacity: .5; }
.lesson-chevron { color: var(--muted); font-size: 22px; }

/* ----- Navigation cards: poker type + unit pickers ----- */
.type-card, .unit-card {
  width: 100%; appearance: none; cursor: pointer;
  display: flex; align-items: center; gap: 13px;
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 16px; margin-bottom: 12px; text-align: left;
  transition: transform .05s ease, box-shadow .15s ease;
  box-shadow: 0 4px 12px rgba(20,40,60,.07);
}
.type-card:active, .unit-card:active { transform: scale(.99); }
.type-card:hover, .unit-card:hover { box-shadow: 0 10px 22px rgba(20,40,60,.12); }
.type-ico {
  width: 46px; height: 46px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--carolina-soft); color: var(--carolina-dark);
  border-radius: 13px; font-size: 24px;
}
.type-body { flex: 1; display: flex; flex-direction: column; }
.type-body b { font-size: 16px; }
.type-body small { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.nav-back {
  appearance: none; border: none; cursor: pointer; background: transparent;
  color: var(--carolina-dark); font-weight: 700; font-size: 14px;
  padding: 4px 0 12px; margin: 0; display: inline-flex; align-items: center;
}
.nav-back:active { opacity: .7; }

.empty {
  border: 1px dashed var(--border); background: #fff; border-radius: 16px;
  padding: 40px 16px; text-align: center; color: var(--muted); font-size: 14px;
}

/* ----- Profile ----- */
.profile-head { display: flex; align-items: center; gap: 15px; margin: 6px 2px 26px; }
.avatar {
  width: 66px; height: 66px; flex: 0 0 auto; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--nu-purple), #6b3fb0);
  color: #fff; font-family: var(--rounded); font-weight: 700; font-size: 28px;
  box-shadow: 0 6px 16px rgba(78,42,132,.32);
}
.profile-id { min-width: 0; }
.profile-name { font-size: 21px; font-weight: 700; line-height: 1.2; word-break: break-word; }
.profile-email { font-size: 13px; color: var(--muted); margin-top: 3px; word-break: break-all; }

.settings-list { display: flex; flex-direction: column; gap: 11px; margin-bottom: 26px; }
.settings-row {
  width: 100%; appearance: none; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2); border: none; border-radius: 14px;
  padding: 16px 16px; text-align: left;
  font-size: 15px; font-weight: 600; color: var(--text);
  transition: background .15s ease, transform .05s ease;
}
.settings-row:hover { background: #e8edf2; }
.settings-row:active { transform: scale(.99); }
.row-left { display: inline-flex; align-items: center; gap: 12px; }
.row-ico { width: 21px; height: 21px; fill: none; stroke: var(--carolina-dark); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row-chevron { color: #b6c1cc; font-size: 22px; line-height: 1; }

.btn-logout {
  width: 100%; appearance: none; border: none; cursor: pointer;
  background: var(--danger); color: #fff; font-weight: 700; font-size: 15px;
  padding: 15px; border-radius: 14px;
  transition: background .15s ease, transform .05s ease;
}
.btn-logout:active { background: var(--danger-press); transform: scale(.99); }

/* ----- bottom tab bar ----- */
.tabbar {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tab {
  appearance: none; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 9px; color: var(--muted); font-size: 11px; font-weight: 600;
  text-decoration: none;
  transition: color .15s ease;
}
.tab .ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--carolina-dark); }

/* ============================================================
   DESKTOP / WIDE SCREENS (>= 820px):
   - navigation moves to a LEFT sidebar (instead of bottom)
   - the app fills the whole screen (no phone frame)
   ============================================================ */
@media (min-width: 820px) {
  body { background: #eef2f6; }

  .view.app {
    max-width: none;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    margin: 0;
    border: none;
    overflow: hidden;
    display: grid;
    grid-template-columns: 248px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "sidebar topbar"
      "sidebar content";
  }

  /* top bar sits above the content column only */
  .topbar { grid-area: topbar; }

  /* the tab bar becomes a full-height left sidebar */
  .tabbar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: 4px;
    grid-template-columns: none;
    background: #fff;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 18px 12px;
  }
  .tab {
    flex-direction: row;
    justify-content: flex-start;
    gap: 14px;
    padding: 13px 16px;
    font-size: 15px;
    border-radius: 12px;
  }
  .tab .ico { width: 22px; height: 22px; }
  .tab:hover { background: #f4f7fa; }
  .tab.active { background: var(--carolina-soft); color: var(--carolina-dark); }

  /* content fills the rest and scrolls; capped for comfortable reading */
  .content { grid-area: content; padding: 30px 40px 40px; }
  .panel { max-width: 760px; }
}

/* ============================================================
   Button depth — soft shadows so controls feel tactile/3D
   ============================================================ */
.btn { box-shadow: 0 6px 16px rgba(59,135,189,.32); }
.btn:active { box-shadow: 0 3px 8px rgba(59,135,189,.30); }
.btn--code { box-shadow: 0 6px 14px rgba(78,42,132,.30); }

.hero-btn { box-shadow: 0 7px 16px rgba(0,0,0,.20); }
.hero-btn:active { box-shadow: 0 3px 8px rgba(0,0,0,.20); }

.lesson-row { box-shadow: 0 4px 12px rgba(20,40,60,.07); }
.lesson-row:hover { box-shadow: 0 10px 22px rgba(20,40,60,.12); }

.settings-row { box-shadow: 0 4px 12px rgba(20,40,60,.08); }
.settings-row:hover { box-shadow: 0 10px 20px rgba(20,40,60,.12); }

.btn-logout { box-shadow: 0 6px 16px rgba(229,72,77,.34); }
.btn-logout:active { box-shadow: 0 3px 8px rgba(229,72,77,.32); }

.tab.active { box-shadow: 0 4px 12px rgba(59,135,189,.20); }

/* ============================================================
   Lesson player
   ============================================================ */
.lesson-pct { font-size: 13px; font-weight: 700; color: var(--carolina-dark); }
.lesson-loading, .lesson-error { padding: 30px 8px; text-align: center; color: var(--muted); }
.lesson-error { color: var(--danger); }

/* ----- lesson player overlay ----- */
.lesson-view {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  background: #fff;
  padding: calc(10px + var(--safe-top)) 0 var(--safe-bottom);
}
.lesson-view[hidden] { display: none; }
.lesson-top { display: flex; align-items: center; gap: 14px; padding: 6px 18px 12px; }
.lesson-close {
  appearance: none; border: none; background: transparent; cursor: pointer;
  font-size: 20px; color: var(--muted); line-height: 1; padding: 4px;
}
.lesson-progress { flex: 1; height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
#lesson-progress-bar { display: block; height: 100%; width: 0; background: var(--carolina); border-radius: 999px; transition: width .3s ease; }

.lesson-content { flex: 1; overflow-y: auto; padding: 14px 22px; width: 100%; max-width: 600px; margin: 0 auto; }
.q-head { font-size: 12px; font-weight: 700; letter-spacing: .5px; color: var(--muted); text-transform: uppercase; }
.q-prompt { font-size: 21px; margin: 8px 0 22px; line-height: 1.35; }
.q-options { display: flex; flex-direction: column; gap: 12px; }
.q-option {
  appearance: none; cursor: pointer; text-align: left;
  background: #fff; border: 2px solid var(--border); border-radius: 14px;
  padding: 16px 16px; font-size: 16px; font-weight: 600; color: var(--text);
  box-shadow: 0 3px 0 var(--border);
  transition: border-color .12s ease, background .12s ease, transform .05s ease;
}
.q-option:hover { border-color: var(--carolina); }
.q-option.selected { border-color: var(--carolina); background: var(--carolina-soft); }
.q-option.correct { border-color: var(--ok); background: #e8f7ee; box-shadow: 0 3px 0 #bfe6cd; }
.q-option.wrong { border-color: var(--danger); background: #fdecea; box-shadow: 0 3px 0 #f3c6c4; }
.q-option:disabled { cursor: default; }

.q-explain { margin-top: 18px; padding: 14px 16px; border-radius: 12px; font-size: 14px; line-height: 1.4; }
.q-explain.good { background: #e8f7ee; color: #1f6e44; }
.q-explain.bad { background: #fdecea; color: #9b2c2c; }

.lesson-foot { padding: 14px 22px calc(18px + var(--safe-bottom)); width: 100%; max-width: 600px; margin: 0 auto; }
.lesson-action { width: 100%; }

.lesson-done { text-align: center; padding: 40px 16px; }
.done-badge {
  width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 36px;
  background: linear-gradient(135deg, var(--gold), #f0a500); color: #fff;
  box-shadow: 0 10px 24px rgba(240,165,0,.4);
}
.lesson-done h2 { margin: 0 0 6px; }
.lesson-done p { color: var(--muted); margin: 0; }

/* ============================================================
   Auth background — soft depth (gradient + blurred glows)
   ============================================================ */
.view.auth {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1100px 560px at 50% -12%, #74b7e2 0%, var(--carolina) 46%, var(--carolina-dark) 100%);
}
.view.auth::before,
.view.auth::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(55px);
  pointer-events: none;
}
.view.auth::before {
  width: 320px; height: 320px;
  background: #cfe6f7; opacity: .55;
  top: -90px; left: -80px;
}
.view.auth::after {
  width: 380px; height: 380px;
  background: var(--nu-purple); opacity: .28;
  bottom: -130px; right: -110px;
}
.auth-card {
  position: relative;
  z-index: 1;
  box-shadow: 0 26px 64px rgba(16,46,76,.34);
}

/* ============================================================
   Lesson teaching content + playing-card chips
   ============================================================ */
.teach-heading { font-size: 20px; margin: 8px 0 14px; }
.teach-body { font-size: 15.5px; line-height: 1.6; color: var(--text); }
.teach-body p { margin: 0 0 12px; }
.teach-body strong { font-weight: 700; }

.hand { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0; }

.pcard {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 40px; height: 56px; margin: 2px; vertical-align: middle;
  background: #fff; border: 1px solid #d4dde6; border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,.12); line-height: 1; font-weight: 800;
}
.pcard.red { color: #d23b3b; }
.pcard.black { color: #1a2733; }
.pc-rank { font-size: 15px; }
.pc-suit { font-size: 18px; margin-top: 3px; }

/* tidy HTML inside quiz prompt / explanation */
.q-prompt p { margin: 0 0 8px; }
.q-prompt p:last-child { margin-bottom: 0; }
.q-explain p { margin: 0; }

/* ============================================================
   LANDING / HOME PAGE (home.html)
   Carolina-blue hero with brand + login.
   ============================================================ */
.home {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #fff;
  background:
    radial-gradient(1200px 620px at 50% -15%, #74b7e2 0%, var(--carolina) 48%, var(--carolina-dark) 100%);
}
/* soft blurred glows for depth (same language as the auth screen) */
.home::before,
.home::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  pointer-events: none;
}
.home::before {
  width: 360px; height: 360px;
  background: #cfe6f7; opacity: .45;
  top: -110px; left: -90px;
}
.home::after {
  width: 420px; height: 420px;
  background: var(--nu-purple); opacity: .26;
  bottom: -150px; right: -120px;
}

/* ---- top nav ---- */
.home-nav {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(18px + var(--safe-top)) 22px 0;
  max-width: 1080px; width: 100%; margin: 0 auto;
}
.home-brand { display: inline-flex; align-items: center; gap: 10px; }
.home-brandname {
  font-family: var(--rounded);
  font-weight: 600; font-size: 20px; letter-spacing: .4px;
}
.home-login-link {
  color: #fff; text-decoration: none; font-weight: 700; font-size: 15px;
  padding: 9px 18px; border-radius: 10px;
  border: 1.5px solid rgba(255,255,255,.55);
  transition: background .15s ease, border-color .15s ease;
}
.home-login-link:hover { background: rgba(255,255,255,.15); border-color: #fff; }

/* ---- hero ---- */
.home-hero {
  position: relative; z-index: 2;
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 40px 22px;
  max-width: 1080px; width: 100%; margin: 0 auto;
}
.home-hero-inner { max-width: 620px; }
.home-kicker {
  font-size: 12px; font-weight: 700; letter-spacing: 2px;
  opacity: .9; margin: 0 0 14px;
}
.home-title {
  font-size: 42px; line-height: 1.12; margin: 0 0 18px;
  font-weight: 800; letter-spacing: -.5px;
  text-shadow: 0 4px 18px rgba(16,46,76,.28);
}
.home-sub {
  font-size: 17px; line-height: 1.55; margin: 0 auto 30px;
  max-width: 500px; opacity: .95;
}
.home-cta {
  display: flex; flex-wrap: wrap; gap: 14px;
  align-items: center; justify-content: center;
}
.home-btn-primary {
  display: inline-block; width: auto;
  background: #fff; color: var(--carolina-dark);
  padding: 15px 40px; font-size: 16px; font-weight: 800;
  border-radius: 12px; text-decoration: none;
  box-shadow: 0 12px 30px rgba(16,46,76,.30);
  transition: transform .06s ease, box-shadow .15s ease;
}
.home-btn-primary:active { transform: scale(.98); }
.home-btn-secondary {
  color: #fff; text-decoration: none; font-weight: 700; font-size: 16px;
  padding: 15px 22px; border-radius: 12px;
  border: 1.5px solid rgba(255,255,255,.6);
  transition: background .15s ease, border-color .15s ease;
}
.home-btn-secondary:hover { background: rgba(255,255,255,.15); border-color: #fff; }
.home-note { margin: 20px 0 0; font-size: 13px; opacity: .82; }

/* ---- footer ---- */
.home-foot {
  position: relative; z-index: 2;
  text-align: center; padding: 18px 0 calc(18px + var(--safe-bottom));
  font-size: 13px; opacity: .82;
}

/* ---- phone screens: tighten the hero ---- */
@media (max-width: 560px) {
  .home-title { font-size: 32px; }
  .home-sub { font-size: 16px; }
  .home-cta { flex-direction: column; }
  .home-btn-primary, .home-btn-secondary { width: 100%; text-align: center; }
}
