/* ===============================
   Design tokens
   =============================== */
:root{
  --font: "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Noto Serif", Georgia, serif;

  --clr-bg: #fafafa;
  --clr-panel: #fff;
  --clr-fg: #222;
  --clr-subtle: #666;
  --clr-border: #d9d9d9;

  --clr-accent: #c00;            /* ← keep the red accent */
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 3px 6px rgba(0,0,0,.06);
  --shadow-hover: 0 6px 14px rgba(0,0,0,.12);

  --pad: 1.5rem;
}

/* ===============================
   Base / reset
   =============================== */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body{
  margin: 0;
  padding: 2rem 1rem;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--clr-fg);
  background: var(--clr-bg);
  font-variant-numeric: tabular-nums;
}

h1,h2,h3{ margin: 0 0 .75rem; line-height: 1.25; font-weight: 700; }
h1{ font-size: clamp(1.8rem, 3.5vw, 2.25rem); text-align: center; }
h2{ font-size: 1.5rem; margin-top: 2rem; }
h3{ font-size: 1.2rem; margin-top: 1.4rem; }

p{ margin: 0 0 .85rem; }
small.hint, p.hint { color: var(--clr-subtle); font-size: .9rem; }

/* ===============================
   Form panel
   =============================== */
#hexForm{
  max-width: clamp(520px, 90vw, 660px);
  margin: 0 auto 2rem;
  padding: 1.25rem var(--pad) 1.5rem;
  background: var(--clr-panel);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);

  display: grid;
  gap: 1.1rem 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

#hexForm > * { min-width: 0; }  /* prevent grid items forcing overflow */

#hexForm label{
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-weight: 600;
}

input[type="number"],
input[type="text"],
select{
  width: 100%;
  padding: .55rem .65rem;
  font: inherit;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

#notationSelect {background: #fafafa;}

input::placeholder{ color: #999; }

input:focus,
select:focus{
  outline: none;
  border-color: var(--clr-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--clr-accent) 28%, transparent);
}

/* Fieldset for six draws */
fieldset{
  grid-column: span 2;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1rem;
}

legend{
  padding: 0 .35rem;
  font-weight: 700;
}

#drawInputs{
  margin-top: .75rem;
  display: grid;
  gap: .55rem;
  grid-template-columns: repeat(6, minmax(3.2rem, 1fr));
}

#drawInputs input[type="number"]{
  text-align: center;
  width: 100%;
}

/* 3×2 layout on narrower screens */
@media (max-width: 800px){
  #drawInputs{ grid-template-columns: repeat(3, 1fr); }
}

/* Submit + Random buttons */
.btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, color .12s ease, border-color .12s ease;
  user-select: none;
}

.btn-primary{
  background: var(--clr-accent);
  color: #fff;
  border-color: var(--clr-accent);
}

.btn-primary:hover{
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.btn-primary:active{
  transform: translateY(0);
  box-shadow: none;
}

.btn-outline{
  background: #fff;
  color: var(--clr-accent);
  border-color: var(--clr-accent);
}

.btn-outline:hover{
  background: #fbeaea;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.btn-outline:active{
  transform: translateY(0);
  box-shadow: none;
}

/* Default: sit side-by-side if there’s room */
button[type="submit"], .btn-random {
  grid-column: auto;         /* ← key change */
  justify-self: stretch;
}

/* Inline code-entry row (label, input, button on one line) */
.code-input{
  min-width: 0;
  grid-column: 1 / -1;
  justify-self: start;     /* don’t stretch horizontally */
  width: max-content;      /* shrink-wrap to content */
  max-width: 100%;         /* avoid overflow on small screens */
  border-top: 1px solid var(--clr-border);
  padding-top: .65rem;
  margin-top: .2rem;
}

.code-row{
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;            /* wraps nicely on small screens */
}

.code-label{
  white-space: normal;
  font-weight: 700;
}

input.code-field[type="text"]{
  flex: 1 1 11ch;
  min-width: 0;
  max-inline-size: 48ch;
  width: auto;
}


/* Safari/WebKit quirk safeguard */
@supports (-webkit-touch-callout: none) {
  .code-row{ overflow: hidden; }  /* makes min-content contribution = 0 */
}

/* Hint line under the row */
.code-input .hint{
  display: block;
  margin-top: .35rem;
}

/* Make the hint wrap under the input only */
.code-input .hint{
  grid-column: 2;          /* the input column */
  justify-self: start;
}


/* ===============================
   Results section
   =============================== */
#results{
  max-width: 980px;           /* same cap as before */
  margin-inline: auto;
  padding-bottom: 4rem;
}

#results p.theme-group{ margin-top: .6rem; }

/* Heading glyph */
.glyph{
  font-size: 2.6rem;
  line-height: 1;
  vertical-align: middle;
  margin-left: .35rem;
}

/* Move highlighting (keep red) */
.moving{
  color: var(--clr-accent);
  font-weight: 700;
}

/* Notation toolbar (compact row) */
.notation-toolbar{
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-top: .25rem;
}

.notation-toolbar select{
  width: auto;
  padding: .4rem .55rem;
}

.notation-out{
  display: inline-block;
  padding: .25rem .5rem;
  border: 1px solid var(--clr-border);
  border-radius: 999px;
  background: #fafafa;
  /*font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;*/
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===============================
   Tables (derived, cycle, flower, story)
   =============================== */
table{
  width: 100%;
  border-collapse: collapse;
  margin: .65rem 0 1.5rem;
  font-size: clamp(.98rem, 3.8vw, 1.08rem);
}

th, td{ padding: .45rem .6rem; text-align: left; }

th{
  border-bottom: 2px solid var(--clr-border);
  font-weight: 700;
}

tr:nth-child(even) td{ background: #f6f6f6; }
tr:hover td{ background: #eee; }

td:last-child{            /* glyph column */
  font-size: 1.35rem;
  white-space: nowrap;
}

/* make long tables scroll on very narrow screens */
@media (max-width: 480px){
  table{ display: block; overflow-x: auto; white-space: nowrap; }
  th, td{ white-space: normal; } /* allow wrapping inside cells */
}

/* ===============================
   Line diagram (keep existing behavior)
   =============================== */
.lines-diagram{
  display: grid;
  grid-template-columns:
    minmax(50px, max-content)  /* bar shrinks first */
    1fr;                        /* text column */
  column-gap: .75rem;
  row-gap: .6rem;
}

.line-row{ display: contents; }

.line-svg{
  width: 100%;
  max-width: 260px;          /* keep current cap */
  height: 12px;              /* fixed height */
  aspect-ratio: auto;        /* allow width to drive */
}

.line-svg rect{ fill: var(--clr-fg); }
.moving .line-svg rect{ fill: var(--clr-accent); }

.line-info{
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===============================
   Slightly denser typography on big screens
   =============================== */
@media (min-width: 900px){
  body{ font-size: 1.0625rem; }
  th, td{ padding: .5rem .75rem; }
}

/* Pick a breakpoint you like; 800px is a good start */
@media (max-width: 800px){
  /* Force each trigram field onto its own row */
  #hexForm label:nth-of-type(1),
  #hexForm label:nth-of-type(2){
    grid-column: 1 / -1;
  }
  #hexForm button[type="submit"],
  #hexForm .btn-random{
    grid-column: 1 / -1;   /* take a whole row each */
  }
  #readBtn{width:100%;}
  fieldset{ grid-column: 1 / -1; }
}

table.trigrams-table td:last-child{ font-size: inherit; white-space: normal; }
table.emblems-table td:last-child{ font-size: inherit; white-space: normal; }