
:root{
  --r: 22px;
  --brand: #2b89fa;
  --brand-dark: #2b89fa;
  --bg: #F6FAFD;
  --card-bg: #FFFFFF;
  --text-main: #0F172A;
  --text-secondary: #00000075;
  --border: rgba(15,23,42,0.10);

  /* === Typography system === */
  --font-base: system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;

  --fw-bold: 950;
  --fw-semibold: 700;
  --fw-regular: 400;

  --fs-24px: 24px;
  --fs-22px: 22px;
  --fs-20px: 20px;
  --fs-18px: 18px;
  --fs-16px: 16px;
  --fs-14px: 14px;

  --color-main: var(--text-main);
  --color-muted: var(--text-secondary);
}

*{ box-sizing:border-box; }
html,
body,
main.wrap{
  height:100%;
}

html,
body{
  min-height: 100vh;
}

@supports (height: 100dvh) {
  html,
  body{
    min-height: 100dvh;
  }
}

body{
  margin:0;
  font-family: var(--font-base);
  background: var(--bg);
  color: var(--color-main);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hidden{ display:none !important; }

.typo-title,
.panelTitle,
.secTitle{
  font-family: var(--font-base);
  font-size: var(--fs-20px);
  font-weight: var(--fw-bold);
  color: var(--color-main);
}

.typo-subtitle,
.hintText,
.meta,
.learnLabel{
  font-family: var(--font-base);
  font-size: var(--fs-16px);
  font-weight: var(--fw-regular);
  color: var(--color-muted);
}

.typo-card-main,
.groupPill {
  font-family: var(--font-base);
  font-size: var(--fs-22px);
  font-weight: var(--fw-semibold);
  color: var(--color-main);
}

.typo-body,
.trans {
  font-family: var(--font-base);
  font-size: var(--fs-16px);
  font-weight: var(--fw-regular);
  color: var(--color-main);
}

.typo-muted,
.setTileCount,
.hint,
.smallNote,
.dictNum{
  font-family: var(--font-base);
  font-size: var(--fs-14px);
  font-weight: var(--fw-regular);
  color: var(--color-muted);
}

/* ---------- TOP ---------- */
.top{
  padding: 2px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  background: var(--bg);
}
.title{
  font-weight: var(--fw-semibold);
  letter-spacing: .2px;
  color: var(--brand-dark);
}
.meta{
  font-size: var(--fs-16px);
  color: var(--color-muted);
  display:flex;
  gap: 10px;
  grid-column: 2;
  justify-self: center;
  text-align: center;
  line-height: 1;
  margin-left: 8px;
  margin-top: -6px;
}


/* ---------- LAYOUT ---------- */
.wrap{
  padding: 6px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.view{ padding-top: 6px; }
.screen{
  height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@supports (height: 100dvh) {
  .screen{
    height: 100dvh;
  }
}

.panel[data-unified-panel="1"]{
  width: 100%;
  height: 90%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.panel-header{
  min-height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 0 solid var(--border);
}

.panel-header .panelTitle{
  margin: 0;
  flex-shrink: 0;
}

.searchInput{
  flex:1;
  height:36px;
  padding:0 12px;
  border-radius:8px;
  border:1px solid #ddd;
  font-size:14px;
}

.panel-body{
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-right:12px;
  padding-left:12px;
  padding-bottom:12px;
}

.panel{
  margin-top: 0px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px;
}

.panelTitle{
  margin-bottom: 12px;
}

/* ---------- STACKS & ROWS ---------- */
.stack{
  display:flex;
  flex-direction:column;
  gap: 10px;
}

.row{
  display:flex;
  gap:10px;
  margin-top: 12px;
}

/* ---------- FIELDS ---------- */
.field{ display:grid; gap:6px; margin:10px 0; }
.field span{ color: var(--color-muted); font-size: var(--fs-16px); }

input{
  width:100%;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(17,169,232,0.06);
  color: var(--color-main);
  outline:none;
}

.hintText{ margin-top:0px; }

/* ---------- BUTTONS ---------- */
.btn{
  flex:1;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--color-main);
  font-weight: var(--fw-semibold);
}
.btn.ghost{
  background: rgba(17,169,232,0.06);
}
.btn.primary,
.btn.secondary{
  background: var(--brand);
  color: #ffffff;
  border: none;
}
.btn.primary:active,
.btn.secondary:active{
  background: var(--brand-dark);
}

.btn.mini{
  flex: 0 0 auto;
  width:100%;
  padding: 10px 12px;
  margin-top: 14px;
  font-weight: var(--fw-semibold);
  background: rgba(17,169,232,0.08);
  border: 1px solid rgba(17,169,232,0.20);
}

.smallNote{
  margin-top: 10px;
  line-height: 1.35;
}

/* ---------- STUDY CARD ---------- */
.card{
  background: var(--card-bg);
  border-radius: var(--r);
  border: 1px solid var(--border);
  user-select:none;
  touch-action: pan-y;
  transition: transform .18s ease, opacity .18s ease;
  position: relative;
}
.card.big{
  min-height: 65vh;
  display:flex;
  flex-direction:column;
}

.word{
  margin-top: 50px;
  text-align:center;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-22px);
}

.hint{
  margin-top: auto;
  padding-top: 12px;
  text-align:center;
}

.trans{
  margin-top: 12px;
  text-align:center;
}

.groupPill .gTrans{
  font-weight: var(--fw-bold);
  font-size: var(--fs-20px)
}

.groupPill .gEx{
  font-size: var(--fs-16px);
  font-weight: var(--fw-regular);
  color: var(--color-muted);
  line-height: 1.3;
  margin-top: 12px;
}

.card{ will-change: transform, opacity; }

.buttons,.footer{ display:flex; gap:10px; margin-top: 12px; }

/* ---------- LIST ---------- */
.list{
  margin-top: 12px;
  border-top: 1px solid var(--border);
  overflow:auto;
}
.item{
  display:grid;
  grid-template-columns: 28px 1fr 44px;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  align-items:center;
}
.item .w{ font-weight: var(--fw-semibold); }
.item .t{ color: var(--color-muted); font-size: var(--fs-16px); margin-top: 2px; }
.checkbox{ width: 18px; height: 18px; }

/* ---------- FAVORITES ---------- */
.favBtn{
  position: absolute;
  top: 10px;
  right: 10px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(17,169,232,0.25);
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(6px);
  font-size: var(--fs-20px);
  font-weight: var(--fw-bold);
  display:flex;
  align-items:center;
  justify-content:center;
}
.favBtn.on{
  background: rgba(17,169,232,0.12);
  border-color: rgba(17,169,232,0.45);
}

.starBtn{
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: #111111;
  display:flex;
  align-items:center;
  justify-content:center;
}

.starBtn .starSvg{
  width: 24px;
  height: 24px;
}

.starBtn.on{
  color: var(--accent);
}

.starBtn.on .starSvg{
  fill: currentColor;
}

/* ---------- TEST ---------- */
.testQuestion{
  margin-top: 10px;
  background: rgba(17,169,232,0.06);
  border: 1px solid rgba(17,169,232,0.20);
  border-radius: 18px;
  padding: 18px 14px;
  font-size: var(--fs-22px);
  font-weight: var(--fw-bold);
  text-align: center;
}

.optionBtn{
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #ffffff;
  font-weight: var(--fw-semibold);
  text-align: center;
}
.optionBtn.correct{
  border-color: rgba(34,197,94,0.45);
  background: rgba(34,197,94,0.12);
}
.optionBtn.wrong{
  border-color: rgba(239,68,68,0.45);
  background: rgba(239,68,68,0.10);
}

/* ---------- TEST LIMIT ---------- */
.testLimitRow{
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.testLimitRadios{
  display: flex;
  gap: 10px;
}
.radioOpt{
  flex: 1;
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #ffffff;
  font-weight: var(--fw-semibold);
}
.radioOpt input{
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--brand);
}


/* ---------- TEST SCOPE ---------- */
.testScopeTitle{
  margin-top: 14px;
}

.scopeBlock{
  margin: 8px 2px;
  padding: 6px;
  border-radius: 16px;
  background: #ffffff;
}
.scopeDictRow,
.scopeSectionRow{
  display:flex;
  align-items:center;
  gap: 10px;
}
.scopeDictRow{ font-weight: var(--fw-bold); }
.scopeSectionRow{
  margin-left: 28px;
  margin-top: 8px;
  font-weight: var(--fw-semibold);
}
.scopeCheckbox{
  width: 18px !important;
  height: 18px !important;
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  accent-color: var(--brand);
  flex: 0 0 auto;
}

.optionBtn.selected{
  border-color: rgba(17,169,232,0.55);
  background: rgba(17,169,232,0.10);
}

.btn:disabled{
  opacity: 0.55;
}

.resultWord{
  font-weight: var(--fw-bold);
  font-size: var(--fs-20px);
}

.resultLine{
  font-weight: var(--fw-regular);
  font-size: var(--fs-16px);
}

.resultLine .lbl{
  font-size: var(--fs-16px);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary)
}

.resultList{
  display:flex;
  flex-direction:column;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

.resultItem{
  display:grid;
  grid-template-columns: 30px 1fr 44px;
  gap: 10px;
  align-items:center;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}

.resultMark{
  width: 24px;
  height: 24px;
  display:flex;
  align-items:center;
  justify-content:center;
  color: var(--color-main);
}

.resultMark.ok{
  color: #22c55e;
 }

.resultMark.bad{
  color: #ef4444;
}

.resultMark svg{
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
}

.analyticsResultItem{
  grid-template-columns: 44px 1fr 44px;
}

.analyticsFailMark{
  width: 38px;
  height: 38px;
  flex-direction: column;
  gap: 2px;
  font-weight: var(--fw-semibold);
}

.analyticsFailMark svg{
  width: 22px;
  height: 22px;
}

.analyticsFailCount{
  font-size: var(--fs-16px);
  line-height: 1;
}


.analyticsTranslation{
  color: var(--color-muted);
}


.dictNumFail svg{
  width: 16px;
  height: 16px;
  vertical-align: text-bottom;
  fill: currentColor;
}


/* ---------- RESPONSIVE ---------- */
@media (max-width: 380px){
  .word{ font-size: calc(var(--fs-20px) * 1.7); }
}

/* --- Global header back arrow --- */
.backArrow{
  appearance:none;
  border:0;
  background:transparent;

  padding:0;
  margin:0;
  border-radius:12px;
  transform: translateY(-2px);
  
  display:inline-flex;
  align-items:center;
  justify-content:center;

  width:auto;
  height:auto;
  line-height:0;

  cursor:pointer;
  user-select:none;
  -webkit-tap-highlight-color: transparent;

  grid-column: 1;
  justify-self: start;
}

.backArrow svg{width:22px;height:22px;fill:currentColor;display:block;}
.backArrow:active{transform:translateX(-2px); opacity:.85;}
.backArrow.hidden{display:none !important;}

/* Old per-screen back buttons are removed from UI (kept in DOM for compatibility) */
button[data-legacy-back="1"]{display:none !important;}



.titleWrap{
  display: contents;
}

.groups{
  margin-top: 10px;
}
.groupRow{
  display:flex;
  align-items: stretch; /* makes left bar equal height */
  gap:10px;
  margin-top:10px;
  margin-left:-8px;
  margin-right:-8px;
}
/* Left number bar (same thickness as pills) */
.groupNum{
  flex: 0 0 24px;
  border-radius: 16px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: var(--fs-16px);
  font-weight: var(--fw-bold);
  color: #ffffff;
  background: var(--brand);
  border: none;
}
/* Translation pill */
.groupPill{
  flex: 1 1 auto;
  width: 100%;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgb(102 210 255 / 16%);
  line-height: 1.3;
  word-break: break-word;
  text-align: left;
}

.exLine{ margin-top: 8px; }
.exLine:first-child{ margin-top: 0; }

/* Remove legacy multi-pill centered layout from study rendering (kept for other views) */
.trans{ text-align: left; }

/* Brand logo */
.brand{
  display:flex;
  align-items:center;
  gap:8px;
  grid-column: 3;
  justify-self: end;
  margin-top: 0;
  transform: translateY(18px)

}

.brandIcon{
  width:48px;
  height:auto;
  display:block;
}


/* === STEP 2: Dictionary content styles (safe append) === */

/* Icon button for header */
.iconBtn{
  appearance:none;
  border:0;
  background:transparent;
  border-radius:12px;
  width:40px;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  -webkit-tap-highlight-color: transparent;
}
.iconBtn svg,
.iconBtn img{
  width:24px;
  height:24px;
  display:block;
}
.iconBtn svg{
  fill: var(--text-secondary);
}
.iconBtn:active{ opacity:.8; }

#viewSections .panel-header #btnOpenDictContent{
  margin-left:auto;
}

/* --- Main screen label: Learn words --- */
.learnLabel{
  margin-top: 14px;
  margin-bottom: 6px;
}


/* Meta placeholders safety */
.meta span{ min-width: 1ch; }


/*** DICTIONARY ***/
#dictContentList{
  border-top: 0px solid var(--border);
}

#dictContentList .sectionHeader{
  padding-top:10px;
  font-weight: var(--fw-semibold);
  color: var(--color-muted);
  cursor:pointer;
  user-select:none;
}

#dictContentList .dictWordRow{
  display: grid;
  grid-template-columns: 28px 1fr 44px;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

#dictContentList .dictWordRow .w{
  font-weight: var(--fw-semibold);
  font-size: var(--fs-16px);
}

#dictContentList .dictWordRow .t{
  margin-top: 2px;
  font-size: var(--fs-16px);
  color: var(--color-muted);
}

#dictContentList .dictNum{
  text-align: right;
}

#viewDicts .panel{
  margin-top: 22px;
}


/* === v9.3 FINAL FIX: correct icon sizing & alignment === */
.subActions .btn{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
}

.subActions .btnLabel{
  display:flex;
  align-items:center;
}

.subActions .btnIcon{
  display:flex;
  align-items:center;
  justify-content:center;
  flex:0 0 auto;
}

.subActions .btnIcon svg{
  width:20px;
  height:20px;
  display:block;
}


/* === v9.5: Flip-card animation === */
.card{
  perspective: 1200px;
}

.cardInner{
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}

.card.flipped .cardInner{
  transform: rotateY(180deg);
}

.cardFace{
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
}

.cardFront{
  justify-content: flex-start;
}

.cardBack{
  transform: rotateY(180deg);
  justify-content: flex-start;
}


/* === v9.5.5 Star toggle fix === */
.starSvg{
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.favAction.active .starSvg{
  fill: currentColor;
  stroke: currentColor;
}


/* === v9.8: Sections + Sets combined grid === */
.secBlock{
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.secBlock:first-child{
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.secTitle{
  margin-bottom: 10px;
}

.setsGrid{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.setTile,
.set-tile{
  --tile-radius: 12px;
  --corner-size: 90cqh;

  position: relative;
  width: 100%;
  box-sizing: border-box;
  aspect-ratio: 1 / 0.15;
  min-height: 50px;
  max-height: 80px;
  container-type: size;

  border-radius: var(--tile-radius);
  border: 1px solid var(--border);
  background: var(--card-bg);

  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.setTile:not(.selected),
.set-tile:not(.selected){
  -webkit-mask:
    radial-gradient(circle at 100% 0, transparent var(--corner-size), #000 calc(var(--corner-size) + 1px)),
    linear-gradient(#000 0 0);
  -webkit-mask-composite: source-over;
  mask:
    radial-gradient(circle at 100% 0, transparent var(--corner-size), #000 calc(var(--corner-size) + 1px)),
    linear-gradient(#000 0 0);
  mask-composite: add;
}

.setDone,
.setTileCorner,
.set-tile__corner{
  position: absolute;
  top: 0;
  right: 0;
  width: var(--corner-size);
  height: var(--corner-size);
  border: 1px solid var(--border);
  margin: -1px;
  padding: 0;
  box-sizing: border-box;
  border-bottom-left-radius: var(--tile-radius);
  border-top-right-radius: var(--tile-radius);
  display:flex;
  align-items:center;
  justify-content:center;
  background: transparent;
  cursor: pointer;
  z-index: 1;
}

.setTile.selected .setDone,
.set-tile.selected .set-tile__corner{
  background: #22c55e;
}

.setTile:active,
.set-tile:active{
  transform: translateY(1px);
}

.setTileTitle{
  font-weight: var(--fw-bold);
  font-size: var(--fs-14px);
  line-height: 1.2;
  padding: 0 2px;
  max-width: calc(100% - 30px);
  margin: 0 auto;

  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}


/* Slightly smaller tiles on very narrow screens */
@media (max-width: 360px){
  .setsGrid{ gap: 8px; }
  .setTileTitle{ font-size: var(--fs-22px); }
}


.setCheck{
  width: 80%;
  height: 80%;
}

.setCheck path{
  stroke: rgba(15,23,42,0.25);
}

.setCheck rect{
    stroke: rgb(255 255 255 / 62%);
}

.setCheck.active path{
  stroke: #22c55e;
}

.setTile.selected .setCheck.active path,
.setTile.selected .setCheck path,
.set-tile.selected .setCheck.active path,
.set-tile.selected .setCheck path{
  stroke: #ffffff;
}

.setTile.selected .setCheck rect,
.set-tile.selected .setCheck rect{
  display: none;
}


/* === v9.9: Match words game === */
.matchColumns{
  display:grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.matchCol{
  display:flex;
  flex-direction:column;
  gap: 10px;
}


.matchCard{
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-weight: var(--fw-semibold);
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select:none;
}

.matchCard:active{ transform: translateY(1px); }

.matchCard.selected{
  border-color: rgba(17,169,232,0.55);
  background: rgba(17,169,232,0.10);
}

.matchCard.matched{
  border-color: rgba(34,197,94,0.45);
  background: rgba(34,197,94,0.12);
}

.matchCard.wrong{
  border-color: rgba(239,68,68,0.45);
  background: rgba(239,68,68,0.10);
}

.noteCenter{ text-align: center; }
.noteTitle{ margin-bottom: 6px; }
.successNoteLine{ font-size: var(--fs-22px); }
.dictNumFail{ color: #ef4444; font-weight: var(--fw-semibold); }

#testOptions.resultScroll{
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

#testOptions.resultScroll .resultList{
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

body.modal-open{
  overflow: hidden;
}

.exitModal{
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.exitModalBackdrop{
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.exitModalCard{
  position: relative;
  width: min(100%, 420px);
  border-radius: 18px;
  background: #ffffff;
  padding: 20px 16px 16px;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.22);
}

.exitModalText{
  text-align: center;
  color: #0f172a;
  font-weight: var(--fw-semibold);
  line-height: 1.45;
}

.exitModalActions{
  display: flex;
  flex-direction: row;
  gap: 14px;
  margin-top: 16px;
}

.exitModalActions .exitStay{
  flex: 1;
  background: #d1d5db;
  color: #111827;
  border-color: #d1d5db;
}

.exitModalActions .exitConfirm{
  flex: 1.5;
}
