/* ICanTalk Keyboard — web version. Black & white, with an Invert colors option. */
:root {
  --bg: #fff; --fg: #000; --dim: #8a8a8a; --red: #ff3b30;
  --dbg: #fff; --dfg: #000; --dsec: #555;
  color-scheme: light;
}
body.dark {
  --bg: #000; --fg: #fff;
  --dbg: #424242; --dfg: #fff; --dsec: #c8c8c8;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
svg { display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

#app { position: fixed; inset: 0; padding: 6px; }
#card {
  position: relative; height: 100%; display: grid; grid-template-columns: 100%;
  border: 2px solid var(--fg); border-radius: 28px; padding: 8px 14px; background: var(--bg);
  --band: 60px; --u: 44px; --kg: 8px;
}
.band { display: flex; align-items: center; min-height: 0; }

/* Display row */
#displayRow { gap: 0; }
.ib {
  width: var(--u); height: var(--u); flex: none; border: 0; padding: 0; background: none;
  color: var(--fg); display: grid; place-items: center;
}
.ib svg { width: 100%; height: 100%; }
.ib[hidden], .key[hidden], #wpm[hidden] { display: none; }
.round { background: var(--fg); color: var(--bg); border-radius: 50%; padding: calc(var(--u) * .1); }
#display {
  flex: 1; min-width: 0; height: calc(100% - 8px); margin: 0 12px; padding: 0 16px;
  border: 2px solid var(--fg); border-radius: 14px; display: flex; align-items: center;
  font-size: calc(var(--band) * .45); font-weight: 500; overflow: hidden; user-select: text;
  -webkit-user-select: text;
}
#displayText { white-space: pre; }
#display.single { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
#display.single::-webkit-scrollbar { display: none; }
#display.wrap { overflow-y: auto; scrollbar-width: none; align-items: flex-start; }
#display.wrap #displayText { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.12; margin: auto 0; }
@keyframes shake { 25% { transform: translateX(7px); } 75% { transform: translateX(-7px); } }
#display.shake { animation: shake .18s; }

/* Suggestion bar / sentence strip */
#suggestionBar { gap: 12px; padding: 4px 0; }
.chip, .strip {
  flex: 1; height: 100%; min-width: 0; border: 2px solid var(--fg); border-radius: 14px;
  background: var(--bg); color: var(--fg); font-weight: 700; font-size: calc(var(--band) * .45);
  display: flex; align-items: center; justify-content: center; padding: 0 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip[hidden] { visibility: hidden; display: flex; }
.strip { cursor: default; }
.strip .dim { color: var(--dim); }
.strip .next { color: var(--red); }

/* Keys */
.krow { display: flex; justify-content: center; gap: var(--kg); padding: 3px 0; min-height: 0; }
.key {
  flex: 0 0 calc((100% - 9 * var(--kg)) / 10); height: 100%; min-width: 0; padding: 0;
  border: 2px solid var(--fg); border-radius: calc(var(--band) * .18);
  background: var(--bg); color: var(--fg); font-weight: 700; font-size: var(--kf, calc(var(--band) * .42));
}
.key:active, .key.lit, .key.on { background: var(--fg); color: var(--bg); }
.key.shift { font-size: var(--kfs, calc(var(--band) * .36)); font-weight: 400; }

/* Bottom row */
#bottomRow { position: relative; padding: 0; }
#leftIcons, #rightIcons { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; gap: 8px; }
#leftIcons { left: 0; } #rightIcons { right: 0; }
#btnSpace {
  position: absolute; top: 4px; bottom: 4px; left: 30%; width: 40%; flex: none; height: auto;
}
#wpm { font-weight: 700; font-size: calc(var(--u) * .42); min-width: calc(var(--u) * 2.1); text-align: right; white-space: nowrap; }

/* Popups */
#toast, #modeToast {
  position: fixed; left: 50%; transform: translateX(-50%); pointer-events: none;
  background: var(--fg); color: var(--bg); border-radius: 16px; font-weight: 500;
  opacity: 0; transition: opacity .2s; z-index: 60; text-align: center;
}
#modeToast { top: 50%; margin-top: -1.4em; padding: .55em 1.3em; font-size: clamp(20px, 4.4vh, 34px); }
#toast { bottom: 9%; padding: .5em 1.1em; font-size: clamp(14px, 2.6vh, 20px); }
#toast.show, #modeToast.show { opacity: 1; }

/* Dialogs */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 10px;
}
.dialog {
  background: var(--dbg); color: var(--dfg); width: min(96vw, 760px); max-height: 96vh;
  border-radius: 6px; padding: 18px 22px 12px; display: flex; flex-direction: column; box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.dialog h2 { margin: 0 0 12px; font-size: 24px; font-weight: 500; }
.dlgBody { min-height: 0; overflow: hidden; display: flex; }
.dlgBtns { display: flex; justify-content: flex-end; gap: 8px; padding-top: 10px; }
.txtBtn { background: none; border: 0; color: var(--dfg); font-weight: 600; font-size: 16px; padding: 10px 14px; text-transform: uppercase; }
.txtBtn:disabled { opacity: .35; cursor: default; }

.settings { height: min(56vh, 330px); width: 100%; }
.nav { width: 130px; flex: none; overflow-y: auto; }
.nav button {
  display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--dfg);
  font-size: 17px; padding: 12px 18px; border-radius: 999px; margin-bottom: 3px;
}
.nav button.sel { background: var(--dfg); color: var(--dbg); font-weight: 600; }
.divider { width: 1px; background: var(--dsec); opacity: .35; margin: 0 12px 0 8px; flex: none; }
.pane { flex: 1; min-width: 0; overflow-y: auto; padding-right: 6px; }
.pane > section[hidden] { display: none; }
.row { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 12px; }
.row label { font-size: 17px; }
.row.disabled { opacity: .4; }
.pill {
  width: 60px; height: 30px; flex: none; border-radius: 15px; border: 2px solid var(--dfg);
  position: relative; background: none; padding: 0; color: var(--dfg);
}
.pill .lbl { position: absolute; top: 0; bottom: 0; display: grid; place-items: center; font-size: 11px; font-weight: 700; width: 30px; }
.pill .thumb { position: absolute; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--dfg); transition: left .12s; }
.pill[aria-checked="true"] { background: var(--dfg); color: var(--dbg); }
.pill[aria-checked="true"] .thumb { background: var(--dbg); left: 34px; }
.pill[aria-checked="true"] .lbl { left: 3px; }
.pill[aria-checked="false"] .thumb { left: 3px; }
.pill[aria-checked="false"] .lbl { right: 3px; }
.pill:disabled { cursor: default; }
.seg { display: flex; gap: 6px; }
.seg button { border: 2px solid var(--dfg); background: none; color: var(--dfg); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.seg button.sel { background: var(--dfg); color: var(--dbg); }
.actBtn { border: 2px solid var(--dfg); background: none; color: var(--dfg); border-radius: 999px; padding: 7px 16px; font-size: 14px; }

.helpBody h3 { margin: 16px 0 0; font-size: 16px; font-weight: 600; }
.helpBody p { margin: 3px 0 0; font-size: 14px; color: var(--dsec); line-height: 1.4; }
.about h1 { font-size: 20px; font-weight: 500; margin: 4px 0 0; }
.about p { margin: 10px 0 0; font-size: 15px; color: var(--dsec); }
.about img { display: block; width: 160px; height: 160px; object-fit: contain; margin: 12px auto 24px; }

/* Help infographic */
.info { width: 100%; height: 120px; margin-bottom: 6px; }
.info text { fill: var(--dsec); font-size: 12px; text-anchor: middle; }
.info .cap { opacity: 0; animation: capfade 9s infinite; }
.info .cap.c2 { animation-delay: 3s; } .info .cap.c3 { animation-delay: 6s; }
@keyframes capfade { 0% { opacity: 0 } 4% { opacity: 1 } 30% { opacity: 1 } 34% { opacity: 0 } 100% { opacity: 0 } }
.info .keyA { animation: keypress 9s infinite; }
@keyframes keypress { 0%,2% { fill: transparent } 6%,14% { fill: var(--dfg) } 18%,100% { fill: transparent } }
.info .w1 { opacity: 0; animation: wave1 9s infinite; }
.info .w2 { opacity: 0; animation: wave2 9s infinite; }
@keyframes wave1 { 0%,12% { opacity: 0 } 18%,30% { opacity: 1 } 36%,100% { opacity: 0 } }
@keyframes wave2 { 0%,66% { opacity: 0 } 72%,94% { opacity: 1 } 100% { opacity: 0 } }
.info .msg { opacity: 0; animation: msgshow 9s infinite; }
@keyframes msgshow { 0%,36% { opacity: 0 } 44%,100% { opacity: 1 } }
.info .spk { animation: spkpulse 9s infinite; transform-origin: 262px 44px; }
@keyframes spkpulse { 0%,60% { transform: scale(1) } 66%,72% { transform: scale(1.18) } 80%,100% { transform: scale(1) } }

/* Alarm timer dialog */
.timer { width: 100%; text-align: center; }
.timer .clock { font-size: 40px; font-weight: 500; margin: 6px 0; }
.timer .steps { display: flex; justify-content: center; gap: 6px; margin: 6px 0; }
.timer .steps .sp { width: 16px; }
.timer .steps button, .timer .go {
  border: 2px solid var(--dfg); background: none; color: var(--dfg); border-radius: 999px;
  padding: 8px 14px; font-size: 16px; font-weight: 600; min-width: 64px;
}
.timer .go { margin-top: 8px; padding: 10px 26px; }
.timer .go:disabled { opacity: .4; }
.timer .ring { font-size: 26px; font-weight: 500; margin: 12px 0; }

@media (max-width: 640px), (max-height: 420px) {
  .dialog { padding: 12px 14px 8px; }
  .settings { height: min(62vh, 300px); }
  .nav { width: 104px; } .nav button { padding: 7px 12px; font-size: 14px; margin-bottom: 2px; }
  .dialog h2 { font-size: 20px; margin-bottom: 6px; }
  .row { min-height: 48px; } .row label { font-size: 15px; }
}

/* [hidden] must win over the display rules above; suggestion chips keep their space. */
[hidden] { display: none !important; }
.chip[hidden] { display: flex !important; visibility: hidden; }

/* Narrow / portrait layout (class set by layout() in app.js): icons on one line, space bar on its own. */
#spacer { display: none; }
#card.narrow #spacer { display: block; }
#card.narrow #bottomRow {
  grid-row: span 2; display: grid; grid-template-rows: 1fr 1fr; grid-template-columns: auto auto;
  justify-content: space-between; align-items: center;
}
#card.narrow #leftIcons, #card.narrow #rightIcons { position: static; grid-row: 1; height: 100%; }
#card.narrow #leftIcons { grid-column: 1; }
#card.narrow #rightIcons { grid-column: 2; }
#card.narrow #btnSpace {
  position: static; grid-row: 2; grid-column: 1 / -1; width: 100%; height: calc(100% - 8px); left: auto;
}
.stepNum { min-width: 28px; text-align: center; font-size: 18px; align-self: center; }
