/* व्याकरण — Grammar (#/grammar, #/grammar/<topic>, #/grammar/machine) */

/* Home */
.gm-group { margin-top: 30px; }
.gm-group .sec-title { margin-bottom: 4px; }
.gm-group .sec-sub { margin: 0 0 14px; color: var(--ink-2); }
.gm-topics { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.gm-topics > li { display: grid; }
.gm-card { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: var(--r-lg); text-decoration: none; color: var(--ink); background: linear-gradient(160deg, var(--h1), var(--surface) 75%); border: 1px solid var(--line); box-shadow: var(--shadow-1); transition: transform .2s var(--spring), box-shadow .2s; min-width: 0; }
.gm-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); }
.gm-card:focus-visible { outline: 3px solid var(--peacock); outline-offset: 3px; }
.gm-card-emoji { font-size: 2rem; line-height: 1; flex: none; }
.gm-card-body { display: grid; gap: 2px; min-width: 0; }
.gm-card-ml { font: 800 1.2rem/1.4 var(--f-ml); color: var(--hi); overflow-wrap: anywhere; }
.gm-card-en { font-weight: 700; }
.gm-card-sub { font-size: .85rem; color: var(--ink-2); overflow-wrap: anywhere; }
.gm-card-sub .ml { font-family: var(--f-ml); }
.gm-card-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }

/* The Tense machine card */
.gm-machine-card { display: flex; align-items: center; gap: 16px; margin-top: 20px; padding: 18px 22px; border-radius: var(--r-lg); text-decoration: none; color: #FFFFFF; background-color: var(--panel); background-image: radial-gradient(circle at 92% 20%, rgba(217,162,27,.35), transparent 45%); box-shadow: var(--shadow-2); min-height: 44px; }
.gm-machine-card > span:nth-child(2) { display: grid; gap: 2px; flex: 1; min-width: 0; }
.gm-machine-card .icon { flex: none; }
.gm-machine-card:focus-visible { outline: 3px solid var(--zari); outline-offset: 3px; }
.gm-machine-emoji { font-size: 2.4rem; line-height: 1; }
.gm-machine-ml { font: 800 1.4rem/1.35 var(--f-ml); color: #FFD77A; }
.gm-machine-en { font-weight: 800; font-size: 1.05rem; }
.gm-machine-note { font-size: .9rem; opacity: .92; }
.gm-machine-card--small { margin: 0; padding: 12px 18px; }
.gm-machine-card--small .gm-machine-ml { font-size: 1.15rem; }

/* A topic */
.gm-hero h1 { margin: 0; }
.gm-hero .h-en { margin: 2px 0 0; }
.gm-hero-sub { color: var(--ink-2); font-weight: 600; }
.gm-hero-sub .ml { font-family: var(--f-ml); }
.gm-hero-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 0; }
.gm-idea { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; border-radius: var(--r-md); background: var(--zari-soft); border: 1px solid color-mix(in srgb, var(--zari) 40%, transparent); font-size: 1.05rem; line-height: 1.65; }
.gm-idea .icon { flex: none; color: var(--zari-deep); margin-top: 3px; }
.gm-idea p { margin: 0; overflow-wrap: anywhere; }
.gm-idea .ml, .gm-tip .ml, .grammar-topic .act-lede .ml, .gm-links .ml { font-family: var(--f-ml); font-weight: 700; color: var(--peacock-deep); }
.gm-tip { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 0; padding: 12px 16px; border-radius: var(--r-md); background: var(--surface); border: 1px dashed var(--line-2); color: var(--ink-2); }
.gm-tip .icon { flex: none; color: var(--marigold); }
.gm-tip span { overflow-wrap: anywhere; }
.gm-links { margin: 0; color: var(--ink-2); font-size: .95rem; }
.gm-links a { display: inline-block; padding: 8px 0; min-height: 44px; box-sizing: border-box; }
.gm-src { margin: 0; color: var(--ink-3); font-size: .82rem; }
.grammar-topic .unit-panel .sec-title { margin: 10px 0 0; }
.gm-table caption { caption-side: top; text-align: left; padding: 10px 14px 6px; font-weight: 800; color: var(--ink); }
.gm-table caption .ml { font-family: var(--f-ml); color: var(--peacock-deep); }
.gm-table th .ml { font-family: var(--f-ml); }
.gm-table td { overflow-wrap: anywhere; }
.gm-table td:not(.ml) { color: var(--ink-2); font-size: .95rem; }
.grammar-topic .letter-nav .ml { font-size: 1.05rem; }
.grammar-topic .letter-nav .btn { max-width: 48%; }
.grammar-topic .letter-nav .btn .ml { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.write-hint { margin: 0; text-align: center; color: var(--ink-3); font-size: .92rem; }
.grammar-topic .write-starter { min-height: 44px; }
.grammar-topic .unit-step { min-height: 64px; }

/* Sentence builder */
.gb { display: grid; gap: 14px; }
.gb .quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.gb-en { margin: 0; font-size: 1.1rem; font-weight: 700; }
.gb-answer { min-height: 72px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px; border-radius: var(--r-md); border: 2px dashed var(--line-2); background: var(--surface); }
.gb-placeholder { color: var(--ink-3); font-size: .95rem; }
.gb-tray { display: flex; flex-wrap: wrap; gap: 10px; min-height: 60px; }
.gb-tile { min-height: 52px; min-width: 44px; padding: 8px 16px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); font: 700 1.2rem/1.4 var(--f-ml); cursor: pointer; box-shadow: 0 3px 0 var(--line-2); transition: transform .15s var(--spring); max-width: 100%; overflow-wrap: anywhere; }
.gb-tile:hover { transform: translateY(-2px); }
.gb-tile:focus-visible { outline: 3px solid var(--peacock); outline-offset: 2px; }
.gb-answer .gb-tile { border-color: var(--peacock); }
.gb-tile.is-right { border-color: var(--leaf); background: var(--leaf-soft); box-shadow: none; }
.gb-tile.is-right::after { content: ' ✓'; font-family: var(--f-ui); color: var(--leaf); }
.gb-tile.is-wrong { border-color: var(--kumkum); background: var(--kumkum-soft); border-style: dashed; }

/* The Tense machine */
.tm-grid { display: grid; gap: 20px; margin-top: 20px; }
@media (min-width: 980px) { .tm-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; } .tm-result { position: sticky; top: 84px; } }
.tm-controls { display: grid; gap: 16px; min-width: 0; }
.tm-label { font: 800 1rem var(--f-ui); margin: 0 0 8px; color: var(--ink-2); }
.tm-label .ml { color: var(--ink); font-family: var(--f-ml); }
.tm-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.tm-chip, .tm-verb, .tm-time { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 14px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 600; font-family: var(--f-ui); }
.tm-chip .ml, .tm-verb .ml, .tm-time .ml { font-family: var(--f-ml); font-size: 1.05rem; }
.tm-chip .en, .tm-verb .en, .tm-time .en { font-size: .78rem; color: var(--ink-3); }
.tm-chip:focus-visible, .tm-verb:focus-visible, .tm-time:focus-visible, .tm-form:focus-visible, .tm-part:focus-visible { outline: 3px solid var(--peacock); outline-offset: 2px; }
.tm-verb { border-radius: 14px; }
.tm-pick:has(> .tm-time) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tm-time { flex-direction: column; justify-content: center; gap: 0; min-height: 56px; padding: 6px 8px; border-radius: 16px; font-size: 1.05rem; }
.tm-emoji { font-size: 1.2rem; }
.tm-pick [aria-pressed="true"] { background: var(--peacock); border-color: transparent; color: var(--on-peacock); }
.tm-pick [aria-pressed="true"] .en { color: inherit; opacity: .9; }
.tm-out { display: grid; gap: 12px; padding: 22px; border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); min-width: 0; }
.tm-sentence { margin: 0; font: 800 clamp(1.4rem, 1.1rem + 1.4vw, 2.1rem)/1.6 var(--f-ml); overflow-wrap: anywhere; }
.tm-part { font: inherit; border: 0; background: none; padding: 0 .1em; border-radius: 8px; cursor: pointer; border-bottom: 4px solid; }
.tmc-who { color: var(--peacock-deep); border-color: var(--peacock); }
.tmc-when { color: var(--zari-deep); border-color: var(--marigold); }
.tmc-what { color: var(--ink); border-color: var(--line-2); border-bottom-style: dotted; }
.tmc-verb { color: var(--kumkum); border-color: var(--kumkum); border-bottom-style: double; }
.tm-en { margin: 0; font-size: 1.1rem; color: var(--ink-2); }
.tm-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.tm-legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.tm-key { font-size: .78rem; font-weight: 700; padding: 2px 10px; border-radius: var(--r-pill); border-bottom: 3px solid; background: var(--ground-2); }
.tm-forms-wrap { margin-top: 28px; }
.tm-forms { display: grid; gap: 10px; }
.tm-forms .sec-title { margin: 0; }
.tm-forms .sec-title .ml { font-family: var(--f-ml); color: var(--peacock-deep); }
.tm-forms .sec-sub { margin: 0; color: var(--ink-2); }
.tm-forms .sec-sub .ml { font-family: var(--f-ml); font-weight: 700; }
.tm-persons-title { margin-top: 16px !important; }
.tm-table th .ml { font-family: var(--f-ml); font-size: 1rem; color: var(--ink); }
.tm-table th .en { font-weight: 600; }
.tm-table td { padding: 4px 6px; }
.tm-form { font: 700 1.05rem/1.4 var(--f-ml); border: 1px solid transparent; background: none; color: var(--ink); padding: 8px 10px; min-height: 44px; border-radius: 10px; cursor: pointer; text-align: left; }
.tm-form:hover { background: var(--ground-2); }
.tm-form.is-on { background: var(--zari-soft); border-color: var(--marigold); }
.tm-person-table tr.is-me th { background: var(--peacock-soft); }
.tm-person-table tr.is-me th .ml { color: var(--peacock-deep); }

/* Phones */
@media (max-width: 560px) {
  .gm-machine-card { padding: 14px 16px; gap: 12px; }
  .gm-machine-emoji { font-size: 2rem; }
  .gm-idea { padding: 14px; font-size: 1rem; }
  .tm-out { padding: 16px; }
  .gb-tile { font-size: 1.1rem; padding: 8px 12px; }
  .lab-table.gm-table th, .lab-table.gm-table td { padding: 8px 10px; }
  .tm-form { font-size: .98rem; padding: 6px 6px; }
}

/* Dark */
:root[data-theme="dark"] .gm-machine-card { color: #EAF5F1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .gm-machine-card { color: #EAF5F1; } }

/* High contrast */
:root[data-contrast="high"] .gm-machine-card { background: #000; background-image: none; color: #fff; border: 2px solid #fff; }
:root[data-contrast="high"] .gm-machine-ml { color: #FFE2A8; }
:root[data-contrast="high"] .gm-card { background: var(--surface); border: 2px solid var(--ink); }
:root[data-contrast="high"] .gm-idea, :root[data-contrast="high"] .gm-tip { border: 2px solid var(--ink); background: var(--surface); }
:root[data-contrast="high"] .tm-pick [aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: 1px; }
:root[data-contrast="high"] .gb-tile { border-color: var(--ink); }
:root[data-contrast="high"] .tm-form.is-on { outline: 3px solid var(--ink); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) { .gm-card, .gb-tile { transition: none; } .gm-card:hover, .gb-tile:hover { transform: none; } }
:root[data-motion="reduced"] .gm-card, :root[data-motion="reduced"] .gb-tile { transition: none; transform: none; }

/* Print */
@media print {
  .gm-machine-card, .tm-actions, .write-actions, .gb-tray, .unit-steps, .letter-nav { display: none !important; }
  .gm-card, .tm-out { box-shadow: none; }
}
@media (max-width: 720px) {
  .grammar-topic .unit-step .ml { overflow-wrap: normal; word-break: keep-all; font-size: .68rem; }
}
@media (max-width: 979px) { .tm-result { order: -1; } }
@media (max-width: 560px) {
  /* Topic tables become cards on phones (app.css); label each cell with its column */
  .lab-table.gm-table tr { grid-template-columns: 1fr; gap: 4px; }
  .lab-table.gm-table td { grid-column: 1 / -1; }
  .lab-table.gm-table td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font: 600 .7rem/1.3 var(--f-ui); color: var(--ink-3); letter-spacing: .02em; }
  .lab-table.gm-table caption { display: block; }
  /* The Tense machine's tables stay real tables */
  .lab-table.tm-table { display: table; }
  .lab-table.tm-table thead { display: table-header-group; }
  .lab-table.tm-table tbody { display: table-row-group; }
  .lab-table.tm-table tr { display: table-row; padding: 0; }
  .lab-table.tm-table th, .lab-table.tm-table td { display: table-cell; padding: 4px; border-top: 1px solid var(--line); vertical-align: middle; }
  .lab-table.tm-table th { font-size: .75rem; }
  .tm-form { font-size: .9rem; padding: 6px 4px; white-space: nowrap; }
  .lab-table.tm-table th .en { display: block; font-size: .65rem; }
  .lab-table.tm-table tbody th .en { display: none; }
  .tm-table { width: max-content; min-width: 100%; }
}
