.gs {
  --gs-ink: var(--cc-text, #1f2430);
  --gs-muted: var(--cc-text-muted, #6b7280);
  --gs-paper: var(--cc-surface, #ffffff);
  --gs-panel: var(--cc-surface-2, #f8f9fc);
  --gs-accent: var(--cc-primary, #4f46e5);
  --gs-accent-dark: var(--cc-primary-dark, #3730a3);
  --gs-line: var(--cc-border, #e7e9f3);
  --gs-radius: var(--cc-radius-sm, 10px);

  color: var(--gs-ink);
  margin-top: 16px;
}

.gs, .gs * { box-sizing: border-box; }

.gs h2 { margin: 0; font-size: 1.05rem; }
.gs-status, .gs-attribution { color: var(--gs-muted); }
.gs a { color: var(--gs-accent); }

.gs-layout { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 12px; }
.gs-drawing { flex: 0 1 380px; min-width: 0; }
.gs-details { flex: 1 1 520px; min-width: 0; }

.gs-pad {
  display: block;
  /* Fills the column, but never taller than most of a short (landscape) screen. */
  width: min(100%, 380px, 75vh);
  aspect-ratio: 1;
  color: var(--gs-ink);
  background: var(--gs-panel);
  border: 1px solid var(--gs-line);
  border-radius: var(--gs-radius);
  touch-action: none; /* stops the page scrolling while you draw */
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.gs-controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; align-items: center; }

.gs button, .gs select, .gs input {
  font: inherit;
  color: inherit;
  background: var(--gs-panel);
  border: 1px solid var(--gs-line);
  border-radius: 8px;
  padding: 4px 10px;
}
.gs button { cursor: pointer; }
.gs button:hover { border-color: var(--gs-accent); }

/* The main action */
.gs .gs-recognize {
  background: var(--gs-accent);
  border-color: var(--gs-accent);
  color: #fff;
  font-weight: 600;
  padding: 4px 16px;
}
.gs .gs-recognize:hover:not(:disabled) { background: var(--gs-accent-dark); border-color: var(--gs-accent-dark); }
.gs button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Results from an earlier drawing */
.gs-results.gs-stale { opacity: 0.45; }

.gs-text { display: block; margin-top: 4px; }
.gs-output { width: 100%; font-size: 1.3rem; margin-top: 4px; }

.gs-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.gs-heading label { font-size: 0.9rem; color: var(--gs-muted); }
.gs-status { font-size: 0.85rem; margin: 4px 0 8px; }

.gs-table-wrap { overflow-x: auto; }
.gs-results { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.gs-results th {
  text-align: left;
  font-weight: 600;
  color: var(--gs-muted);
  border-bottom: 1px solid var(--gs-line);
  padding: 2px 6px;
}
.gs-results td { padding: 2px 6px; border-bottom: 1px solid var(--gs-line); vertical-align: middle; }
.gs-results .gs-score { text-align: left; color: var(--gs-muted); }
.gs-results .gs-code { white-space: nowrap; }
.gs-results .gs-glyph-box { display: flex; flex-wrap: nowrap; align-items: center; gap: 4px; }
.gs-results .gs-glyph-box button { flex: none; }

/* Copy: just the icon, no box around it. Size/padding live only in the base rule
   (not :hover), so the media-query overrides below keep applying on hover. */
.gs .gs-copy-btn {
  background: none;
  border: 0;
  padding: 0 2px;
  min-width: 0;
  min-height: 0;
  line-height: 1;
}
.gs .gs-copy-btn:hover { background: none; border: 0; opacity: 0.65; }
.gs-results .gs-name { max-width: 17rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gs-results td button { padding: 2px 6px; }
.gs-results .gs-char { font-size: 1.4rem; min-width: 2.4rem; line-height: 1.2; }
.gs-results .gs-tile { font-size: 1.1rem; min-width: 2.6rem; position: relative; padding-right: 18px; }
.gs-results .gs-more { position: absolute; right: 3px; bottom: 1px; font-size: 0.65rem; color: var(--gs-muted); }
.gs-results a { white-space: nowrap; }

.gs-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Look-alikes popup */
.gs-chooser {
  position: fixed;
  z-index: 1000;
  max-width: min(360px, calc(100vw - 32px));
  max-height: min(420px, calc(100vh - 32px)); /* big groups scroll inside the popup */
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--gs-paper);
  border: 1px solid var(--gs-line);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.2);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.gs-chooser[hidden] { display: none; }
.gs-chooser button { flex: none; display: flex; gap: 10px; align-items: baseline; text-align: left; border: none; }
.gs-chooser-char { font-size: 1.5rem; width: 2rem; }
.gs-chooser-name { font-size: 0.8rem; color: var(--gs-muted); }

.gs-attribution { margin-top: 32px; font-size: 0.8rem; }
.gs-attribution p { margin: 4px 0; }

/* Example prompt above the tool */
.gs-example { color: var(--cc-text-muted, #6b7280); }
.gs-example-char {
  display: inline-block;
  min-width: 1.9em;
  padding: 0 6px;
  text-align: center;
  font-size: 1.15em;
  line-height: 1.6;
  color: var(--cc-text, #1f2430);
  background: var(--cc-surface-2, #f8f9fc);
  border: 1px solid var(--cc-border, #e7e9f3);
  border-radius: 8px;
}

/* "How to use" section under the tool */
.gs-help { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--cc-border, #e7e9f3); }
.gs-help h2 { font-size: 1.45rem; margin: 0 0 12px; }
.gs-help h3 { font-size: 1.25rem; margin: 24px 0 8px; }
.gs-help ol, .gs-help ul { padding-left: 1.4em; margin: 0; }
.gs-help li { margin-bottom: 8px; }

/* "Supported Scripts" section */
.gs-scripts { margin-top: 32px; border-top: 1px solid var(--cc-border, #e7e9f3); }
.gs-scripts h2 { font-size: 1.45rem; margin: 0 0 12px; }
.gs-scripts h3 { font-size: 1.25rem; margin: 20px 0 8px; }
.gs-scripts details {
  background: var(--cc-surface-2, #f8f9fc);
  border: 1px solid var(--cc-border, #e7e9f3);
  border-radius: var(--cc-radius-sm, 10px);
  padding: 10px 16px; margin-top:20px;
}
.gs-scripts summary { cursor: pointer; font-weight: 600; color: var(--cc-primary, #4f46e5); }
.gs-scripts details[open] summary { margin-bottom: 4px; }
.gs-script-list {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 15rem; /* as many columns as fit */
  column-gap: 24px;
}
.gs-script-list li { break-inside: avoid; padding: 1px 0; }
.gs-count { color: var(--cc-text-muted, #6b7280); font-size: 0.85em; }
.gs-scripts-note { margin: 16px 0 0; color: var(--cc-text-muted, #6b7280); }

/* ------------------------------------------------------------------ */
/* Responsive layout                                                  */
/* ------------------------------------------------------------------ */

/* Tablets and down: the pad and the results stack. Let the pad use the width. */
@media (max-width: 900px) {
  .gs-drawing { flex-basis: 100%; }
  .gs-pad { width: min(100%, 460px, 75vh); }
  .gs-output { max-width: 460px; }
}

/* Touch screens of any size: finger-sized targets. 16px fonts stop iOS zooming into fields. */
@media (pointer: coarse) {
  .gs button, .gs select, .gs input { min-height: 44px; font-size: 16px; }
  .gs-results td button { min-width: 44px; }
  .gs .gs-copy-btn { min-width: 40px; min-height: 44px; padding: 0; }
  .gs-results a { display: inline-block; padding: 10px 4px; }
}

/* Phones */
@media (max-width: 640px) {
  .gs { margin-top: 8px; }
  .gs-layout { gap: 16px; }
  .gs-pad { width: min(100%, 75vh); }
  .gs-output { max-width: none; }

  /* Bigger touch targets; 16px+ fonts stop iOS zooming in when a field is focused. */
  .gs button, .gs select, .gs input { min-height: 44px; font-size: 16px; }
  .gs-controls { gap: 8px; }
  .gs-drawing .gs-controls button { flex: 1 1 0; padding-left: 8px; padding-right: 8px; }

  /* Results: one card per candidate instead of a table.
     Row 1: char + copy | name        | look-alikes
     Row 2: char + copy | code (link) | score */
  .gs-table-wrap { overflow: visible; }
  .gs-results, .gs-results tbody { display: block; width: 100%; }
  .gs-results thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); /* hidden visually, kept for screen readers */
  }
  .gs-results tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 2px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--gs-line);
  }
  .gs-results td { display: block; padding: 0; border: 0; min-width: 0; }

  .gs-results .gs-glyph { grid-column: 1; grid-row: 1 / span 2; }
  .gs-results .gs-name  { grid-column: 2; grid-row: 1; max-width: none; white-space: normal; overflow: visible; font-weight: 600; line-height: 1.25; }
  .gs-results .gs-code  { grid-column: 2; grid-row: 2; }
  .gs-results .gs-look  { grid-column: 3; grid-row: 1; }
  .gs-results .gs-score { grid-column: 3; grid-row: 2; text-align: right; }
  .gs-results .gs-score::before { content: "score "; }

  .gs-results td button { min-width: 44px; }
  .gs .gs-copy-btn { min-width: 40px; min-height: 44px; padding: 0; } /* finger-sized, but no visible box */
  .gs-results .gs-char { font-size: 1.9rem; width: 3.4rem; min-height: 3.4rem; }
  .gs-results .gs-tile { min-width: 44px; padding-right: 20px; }
  .gs-results .gs-code a { display: inline-block; padding: 8px 0; }

  /* Look-alike list: a sheet at the bottom of the screen, easy to reach and to scroll. */
  .gs-chooser.gs-sheet {
    left: 8px; right: 8px; top: auto; bottom: 8px;
    max-width: none;
    max-height: 55vh;
    box-shadow: 0 -6px 30px rgb(0 0 0 / 0.25);
  }
  .gs-chooser button { padding: 10px 8px; }

  .gs-scripts details { padding: 10px 12px; }
  .gs-script-list { columns: 11rem; }
}

/* Very narrow phones */
@media (max-width: 360px) {
  .gs-results .gs-char { width: 2.9rem; }
  .gs-results .gs-glyph-box { gap: 0; }
}

/* Visitors who ask their device for less motion get no smooth scrolling. */
@media (prefers-reduced-motion: reduce) {
  .gs * { scroll-behavior: auto !important; }
}