/* Grammar guide (js/grammar.js) */
.gr-lib, .gr-rule { display: grid; gap: 20px; min-width: 0; }
.gr-rule { max-width: 780px; margin-inline: auto; width: 100%; }
.gr-en { font-family: var(--font-target); font-weight: 600; color: var(--ink); unicode-bidi: isolate; white-space: normal; }

/* library: hero */
.gr-hero { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 22px 20px; border-radius: 26px; overflow: hidden;
  background: radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--ok) 14%, transparent), transparent 60%),
              radial-gradient(120% 140% at 100% 100%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%), var(--surface);
  border: 1px solid color-mix(in srgb, var(--rule) 60%, transparent); box-shadow: var(--shadow); }
.gr-hero-txt { display: grid; gap: 8px; min-width: 0; justify-items: start; }
.gr-kicker { font: 700 .78rem/1 var(--font-target); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.gr-hero h1 { margin: 0; font-family: var(--font-display); font-size: clamp(1.6rem, 4vw, 2.3rem); }
.gr-hero .lead { margin: 0; max-width: 52ch; color: var(--muted); }
.gr-hero-art { flex: none; width: 92px; height: 92px; object-fit: cover; object-position: 50% 40%; border-radius: 24px; transform: rotate(3deg);
  box-shadow: 0 18px 36px -20px var(--accent); border: 3px solid var(--surface); background: #fff; align-self: flex-start; }
.gr-prog { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; width: 100%; }
.gr-meter { flex: 1 1 140px; max-width: 260px; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.gr-meter span { display: block; height: 100%; border-radius: inherit; background: var(--ok); min-width: 4px; transition: width .4s ease; }
.gr-cta { margin-top: 6px; max-width: 100%; display: inline-grid; gap: 4px; justify-items: start; padding: .75em 1.4em; white-space: normal; line-height: 1.25; text-align: start; border-radius: 20px; }
.gr-cta-k { font-size: .8rem; font-weight: 600; opacity: .85; }
.gr-cta-t { font: 700 1.05rem/1.25 var(--font-target); }
[dir="rtl"] .gr-cta-t { text-align: right; }
.gr-result-acts .gr-cta .gr-cta-t { text-align: center; }
.gr-all-done { margin: 4px 0 0; font-weight: 600; color: var(--ok); }

/* library: level groups and topic cards */
.gr-group { display: grid; gap: 12px; }
.gr-group-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 0; font-size: 1.25rem; }
.gr-group-n { margin-inline-start: auto; font-family: var(--font-body); }
.gr-mine { background: color-mix(in srgb, var(--lv, var(--accent)) 18%, var(--surface)); color: var(--ink); font-weight: 600; font-family: var(--font-body); }
.gr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 14px; }
.gr-card { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 18px 18px 16px; border-radius: 22px; background: var(--surface); cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--rule) 60%, transparent); box-shadow: var(--shadow); overflow: hidden; transition: transform .15s ease, box-shadow .2s ease, border-color .2s; min-width: 0; }
.gr-card::before { content: ''; position: absolute; inset: 0 0 auto; height: 4px; background: var(--lv, var(--accent)); opacity: .85; }
.gr-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--lv, var(--accent)) 45%, transparent); }
.gr-card.is-done { background: linear-gradient(170deg, color-mix(in srgb, var(--ok) 7%, var(--surface)), var(--surface) 55%); }
.gr-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gr-num { font: 800 1.5rem/1 var(--font-target); color: color-mix(in srgb, var(--lv, var(--accent)) 70%, var(--muted)); letter-spacing: -.02em; }
.gr-new { background: color-mix(in srgb, var(--lv, var(--accent)) 14%, var(--surface-2)); color: var(--ink); font-weight: 600; }
.gr-card h3 { margin: 4px 0 0; font: 700 1.14rem/1.25 var(--font-target); text-align: left; overflow-wrap: anywhere; }
[dir="rtl"] .gr-card h3 { text-align: right; }
.gr-card .gr-tr { margin: 0; font-weight: 500; color: var(--ink); }
.gr-card-lead { margin: 2px 0 0; color: var(--muted); font-size: .92rem; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.gr-card-lead .gr-en { color: var(--muted); font-weight: 600; }
.gr-foot { margin-top: auto; padding-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* one topic */
.gr-topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.gr-head { display: grid; gap: 8px; justify-items: center; text-align: center; padding: 6px 4px 2px; }
.gr-head h1 { margin: 2px 0 0; font: 800 clamp(1.6rem, 5vw, 2.4rem)/1.15 var(--font-target); letter-spacing: -.01em; overflow-wrap: anywhere; }
.gr-head .gr-tr { margin: 0; color: var(--muted); font-size: 1.05rem; font-weight: 500; }
.gr-lead { margin: 6px 0 0; max-width: 60ch; font-size: 1.08rem; line-height: 1.65; }
.gr-panel { background: var(--surface); border-radius: 22px; padding: 18px 16px; display: grid; gap: 12px; min-width: 0;
  border: 1px solid color-mix(in srgb, var(--rule) 60%, transparent); box-shadow: var(--shadow); }
.gr-panel h2 { margin: 0; font-size: 1.2rem; display: flex; align-items: center; gap: 10px; }
.gr-panel h2::before { content: ''; width: 6px; height: 1.1em; border-radius: 3px; background: var(--lv, var(--accent)); flex: none; }

.gr-rules ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; counter-reset: gr; }
.gr-rules li { counter-increment: gr; position: relative; padding-inline-start: 40px; line-height: 1.65; min-height: 28px; overflow-wrap: anywhere; }
.gr-rules li::before { content: counter(gr); position: absolute; inset-inline-start: 0; top: .1em; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font: 700 .85rem/1 var(--font-target); color: var(--ink); background: color-mix(in srgb, var(--lv, var(--accent)) 20%, var(--surface-2)); }

.gr-table-wrap { direction: ltr; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 16px; border: 1px solid var(--rule); overscroll-behavior-x: contain; }
.gr-table-wrap:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.gr-table { width: 100%; border-collapse: collapse; text-align: left; font: 500 .95rem/1.35 var(--font-target); color: var(--ink); }
.gr-table th, .gr-table td { padding: 9px 10px; border-bottom: 1px solid color-mix(in srgb, var(--rule) 70%, transparent); vertical-align: top; overflow-wrap: normal; word-break: normal; }
.gr-table thead th { background: color-mix(in srgb, var(--lv, var(--accent)) 14%, var(--surface-2)); font-weight: 700; font-size: .85rem; letter-spacing: .02em; }
.gr-table tbody th { font-weight: 700; color: var(--ink); background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.gr-table tbody tr:last-child > * { border-bottom: 0; }
.gr-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 35%, var(--surface)); }

.gr-examples ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.gr-examples li { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; border-radius: 16px; background: var(--surface-2); }
.gr-examples .speak { flex: none; margin-top: 2px; }
.gr-ex { flex: 1; min-width: 0; display: grid; gap: 2px; }
.gr-ex-t { appearance: none; border: 0; background: none; padding: 2px 4px; margin: 0 -4px; border-radius: 8px; cursor: pointer; color: var(--ink);
  font: 600 1.06rem/1.45 var(--font-target); text-align: left; justify-self: start; max-width: 100%; overflow-wrap: anywhere; transition: background-color .15s; }
.gr-ex-t:hover { background: color-mix(in srgb, var(--lv, var(--accent)) 14%, transparent); }
.gr-ex-tr { color: var(--muted); font-size: .95rem; line-height: 1.45; overflow-wrap: anywhere; }
.gr-examples > p { margin: 0; }

.gr-tip { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: 22px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 13%, var(--surface)), color-mix(in srgb, var(--accent) 5%, var(--surface)));
  border: 1.5px solid color-mix(in srgb, var(--accent) 35%, transparent); box-shadow: var(--shadow); }
.gr-tip img { flex: none; width: 76px; height: 76px; object-fit: cover; object-position: 50% 30%; border-radius: 50%; background: #fff;
  border: 3px solid var(--surface); box-shadow: 0 10px 22px -14px var(--accent); }
.gr-tip > div { min-width: 0; display: grid; gap: 6px; }
.gr-tip-k { margin: 0; font: 700 .82rem/1.2 var(--font-body); letter-spacing: .04em; color: var(--accent); }
.gr-tip-k::before { content: '!'; display: inline-grid; place-items: center; width: 1.35em; height: 1.35em; margin-inline-end: 6px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font: 800 .8rem/1 var(--font-target); vertical-align: 1px; }
.gr-tip-t { margin: 0; line-height: 1.7; overflow-wrap: anywhere; }

/* practice */
.gr-quiz { scroll-margin-top: 150px; gap: 14px; }
.gr-quiz-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gr-quiz-head p { margin: 4px 0 0; }
.gr-dots { list-style: none; margin: 4px 0 0; padding: 0; display: flex; gap: 6px; }
.gr-dots li { width: 12px; height: 12px; border-radius: 50%; background: var(--surface-2); border: 1.5px solid var(--rule); transition: background-color .2s, transform .2s; }
.gr-dots li.now { border-color: var(--lv, var(--accent)); background: color-mix(in srgb, var(--lv, var(--accent)) 30%, var(--surface)); transform: scale(1.15); }
.gr-dots li.ok { background: var(--ok); border-color: var(--ok); }
.gr-dots li.bad { background: var(--bad); border-color: var(--bad); }
.gr-qcard { display: grid; gap: 12px; padding: 16px; border-radius: 18px; background: var(--surface-2); }
.gr-qn { margin: 0; }
.gr-q { margin: 0; text-align: left; font: 600 clamp(1.15rem, 3.4vw, 1.4rem)/1.5 var(--font-target); color: var(--ink); overflow-wrap: anywhere; }
.gr-blank { display: inline-block; min-width: 3.2em; padding: 0 .3em; margin: 0 .1em; border-bottom: 3px solid var(--lv, var(--accent)); line-height: 1.2; text-align: center; }
.gr-blank.is-filled { color: var(--ok); border-bottom-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); border-radius: 6px 6px 0 0; }
.gr-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.gr-opt { flex: 1 1 0; min-width: max-content; display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 10px 12px; text-align: left; font: 600 1.05rem/1.3 var(--font-target); background: var(--surface); }
.gr-opts.is-long { display: grid; grid-template-columns: minmax(0, 1fr); }
.gr-opts.is-long .gr-opt { min-width: 0; }
.gr-opt-t { flex: 1; min-width: 0; overflow-wrap: break-word; hyphens: none; }
.gr-key { flex: none; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font: 700 .72rem/1 var(--font-body); color: var(--muted);
  border: 1px solid var(--rule); background: var(--surface-2); }
.gr-opt.right .gr-key { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.gr-opt.wrong .gr-key { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.gr-opt.dim { opacity: .55; }
.gr-opt.wrong .gr-opt-t { text-decoration: line-through; text-decoration-thickness: 2px; text-decoration-color: color-mix(in srgb, var(--bad) 70%, transparent); }
.gr-keys { margin: 0; }
@media (hover: none), (max-width: 480px) { .gr-keys, .gr-key { display: none; } }
.gr-fb { display: grid; gap: 4px; padding: 12px 14px; border-radius: 14px; border-inline-start: 4px solid; animation: gr-in .25s ease; }
.gr-fb.ok { background: var(--ok-soft); border-color: var(--ok); }
.gr-fb.bad { background: var(--bad-soft); border-color: var(--bad); }
.gr-fb-h { margin: 0; font-weight: 700; }
.gr-fb.ok .gr-fb-h { color: var(--ok); } .gr-fb.bad .gr-fb-h { color: var(--bad); }
.gr-fb-why { margin: 0; line-height: 1.6; color: var(--ink); }
.gr-qnext { display: flex; justify-content: flex-end; }
.gr-qnext .btn { min-width: 160px; }
@keyframes gr-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* result */
.gr-result { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 18px 14px; border-radius: 20px;
  background: linear-gradient(170deg, color-mix(in srgb, var(--ok) 12%, var(--surface-2)), var(--surface-2)); animation: gr-in .3s ease; }
.gr-result-top { position: relative; display: flex; align-items: center; justify-content: center; gap: 14px; }
.gr-result-top img { width: 96px; height: 96px; object-fit: cover; border-radius: 26px; background: #fff; border: 3px solid var(--surface); }
.gr-ring { --p: 0%; width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--ok) var(--p), var(--surface) 0); }
.gr-ring span { width: 76px; height: 76px; border-radius: 50%; display: flex; align-items: baseline; justify-content: center; padding-top: 22px; background: var(--surface-2); font: 600 1.05rem/1 var(--font-target); color: var(--muted); direction: ltr; }
.gr-ring b { font-size: 1.8rem; color: var(--ink); }
.gr-score { margin: 4px 0 0; font-size: 1.2rem; font-weight: 700; }
.gr-tier { margin: 0; max-width: 46ch; }
.gr-result-badges { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 4px; }
.gr-gems { display: inline-block; font-weight: 700; padding: .3em .9em; border-radius: 999px; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.gr-result-acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.gr-result-acts .btn { max-width: 100%; white-space: normal; line-height: 1.3; }
.gr-result-acts .gr-cta { margin-top: 0; flex-basis: 100%; justify-items: center; text-align: center; }
.gr-review { width: 100%; text-align: start; margin-top: 6px; }
.gr-review summary { cursor: pointer; font-weight: 600; color: var(--muted); padding: 6px 2px; }
.gr-review ol { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.gr-review li { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 12px; background: var(--surface); font: 500 1rem/1.45 var(--font-target); }
.gr-review li > span[dir] { flex: 1; min-width: 0; text-align: left; overflow-wrap: anywhere; }
.gr-mark { flex: none; font-weight: 800; }
.gr-review li.ok .gr-mark { color: var(--ok); } .gr-review li.bad .gr-mark { color: var(--bad); }
.gr-review .gr-blank { min-width: 0; }

/* games page card */
.g-grammar .gr-game-art { width: 100%; height: 120px; object-fit: contain; object-position: 50% 50%; border-radius: 16px; background: #fff; padding: 4px 0; }

@media (min-width: 641px) {
  .gr-hero { padding: 26px 28px; }
  .gr-hero-art { width: 150px; height: 150px; border-radius: 30px; align-self: center; }
  .gr-panel { padding: 20px 22px; }
  .gr-tip { padding: 18px 20px; align-items: center; }
  .gr-tip img { width: 104px; height: 104px; }
  .gr-qcard { padding: 18px 20px; }
  .gr-table th, .gr-table td { padding: 10px 14px; }
  .gr-result { grid-template-columns: auto 1fr; text-align: start; justify-items: start; column-gap: 22px; padding: 22px; }
  .gr-result-top { grid-row: span 4; }
  .gr-result-badges, .gr-result-acts { justify-content: flex-start; }
  .gr-review { grid-column: 1 / -1; }
}
@media (max-width: 380px) {
  .gr-table { font-size: .86rem; }
  .gr-table thead th { font-size: .78rem; letter-spacing: 0; }
  .gr-table th, .gr-table td { padding: 8px 6px; }
  .gr-ring { width: 84px; height: 84px; } .gr-ring span { width: 66px; height: 66px; }
  .gr-result-top img { width: 84px; height: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  .gr-card, .gr-meter span, .gr-dots li { transition: none; }
  .gr-card:hover { transform: none; }
  .gr-fb, .gr-result { animation: none; }
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) :is(.gr-hero-art, .gr-tip img, .gr-game-art, .gr-result-top img) { filter: brightness(.86); } }
:root[data-theme="dark"] :is(.gr-hero-art, .gr-tip img, .gr-game-art, .gr-result-top img) { filter: brightness(.86); }
