/* Shared page chrome. Game boards keep their own sizing, artwork and behavior. */
html { color: #283d32; background: #faf7ef; }
.home h1 { color: #254f39; }
.tool-page { max-width: 920px; margin: 0 auto; padding: 6px 12px; }
.tool-page.pad-page { width: 100%; max-width: 1224px; }
html[lang] .tool-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "home title new language";
  align-items: center;
  gap: 4px 8px;
  margin: 0 0 2px;
  padding: 0;
}
html[lang] .tool-header--pad {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "home title language";
}
html[lang] .tool-header h1 {
  grid-area: title;
  align-self: center;
  min-width: 0;
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
  color: #254f39;
  overflow-wrap: break-word;
}
html[lang] .tool-header .tool-home {
  grid-area: home;
  align-self: start;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  margin: 0;
  padding: 0 4px;
  font: 700 24px/1.3 Arial, "Noto Sans TC", sans-serif;
  color: #315a47;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
html[lang] .tool-header #new-game {
  grid-area: new;
  align-self: start;
  justify-self: end;
  min-height: 48px;
  padding: 6px 10px;
  border: 2px solid #254532;
  border-radius: 10px;
  color: #fffdf7;
  background: #315a47;
  font: 700 20px/1.3 Arial, "Noto Sans TC", sans-serif;
  white-space: nowrap;
}
/* Include the directory and typing pad: native button defaults must not leak in. */
html[lang] body #language-toggle {
  grid-area: language;
  align-self: start;
  justify-self: end;
  min-height: 48px;
  padding: 6px 10px;
  border: 2px solid #45654e;
  border-radius: 10px;
  color: #283d32;
  background: #fffdf7;
  font: 18px/1.3 Arial, "Noto Sans TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
html[lang] .tool-header #language-toggle { grid-area: language; }
.tool-page .secondary, .tool-page .footer-tools { gap: 8px; }
.tool-page .secondary { margin-top: 8px; }
.tool-page .secondary > button, .tool-page .footer-tools > button,
.tool-page .actions > button, .dialog-actions > button {
  min-height: 48px;
  padding: 8px 12px;
  border-width: 2px;
  border-radius: 10px;
  font-size: 20px;
  line-height: 1.3;
}
.tool-page .actions > button { padding: 6px 3px; }
/* Text actions need their intrinsic width; do not squeeze them to a digit key. */
.tool-page .controls:not(.direction-pad) button { flex-basis: auto; }
.tool-page details { font-size: 20px; line-height: 1.5; }
.tool-page summary { min-height: 48px; padding: 10px 4px; }
.tool-page .status, .tool-page .status-line { gap: 4px 16px; margin: 6px 0 0; font-size: 18px; line-height: 1.4; }
.tool-page #offline-status, .tool-page #save-status { font-size: 18px; line-height: 1.4; }
.dialog, .dialog-card { max-width: 480px; padding: 22px; border: 3px solid #45654e; border-radius: 14px; background: #fffdf7; }
.dialog h2, .dialog-card h2 { margin: 0 0 12px; font-size: 26px; line-height: 1.3; }
.dialog p, .dialog-card p { font-size: 20px; line-height: 1.5; }
.dialog-actions { gap: 12px; }
.dialog-actions > button { font-family: Arial, "Noto Sans TC", sans-serif; }
.tool-home:focus-visible, #language-toggle:focus-visible { outline: 3px dashed #111; outline-offset: 3px; }
/* Home stays at the top left in both languages, even when titles need two rows. */
@media (max-width: 559px) {
  html[lang] .tool-header {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "home language" "title new";
  }
  html[lang] .tool-header--pad { grid-template-areas: "home language" "title title"; }
  html[lang] .tool-header h1 { font-size: 24px; }
}
@media (max-width: 419px) {
  .tool-page { padding: 6px 8px; }
  .dialog, .dialog-card { padding: 16px; }
}
/* Browsers without flexbox gap (Chrome before 84, such as the Kindle's Silk 80) would set these buttons and status
   lines edge to edge. They also lack aspect-ratio (Chrome 88), which @supports can test, so there margins give the
   same spacing: half of each gap on both sides of every item, taken back at the row's ends, keeps wrapped rows even.
   The gaps are cleared for browsers that have flexbox gap but not aspect-ratio. Newer browsers never use these rules,
   and Kobo keeps its own layout (kobo.css). */
@supports not (aspect-ratio: 1 / 1) {
  html:not(.readerplay-kobo) .tool-page .secondary, html:not(.readerplay-kobo) .tool-page .footer-tools { gap: 0; margin-right: -4px; margin-left: -4px; }
  html:not(.readerplay-kobo) .tool-page .secondary > *, html:not(.readerplay-kobo) .tool-page .footer-tools > * { margin-right: 4px; margin-left: 4px; }
  html:not(.readerplay-kobo) .tool-page .secondary > details[open], html:not(.readerplay-kobo) .tool-page .footer-tools > details[open] { margin-top: 8px; }
  html:not(.readerplay-kobo) .tool-page .status, html:not(.readerplay-kobo) .tool-page .status-line { gap: 0; margin: 4px -8px -2px; }
  html:not(.readerplay-kobo) .tool-page .status > *, html:not(.readerplay-kobo) .tool-page .status-line > * { margin: 2px 8px; }
  html:not(.readerplay-kobo) .dialog-actions { gap: 0; }
  html:not(.readerplay-kobo) .dialog-actions > * + * { margin-left: 12px; }
}
