:root {
  --bg: #dde6e8;
  --btn: #84bac7;
  --btn-text: #fff;
  --ink: #333;
  --phrase-h: 22vh;
  --actions-w: 10%;
  --gap: 4px;
  --rows: 6;
  --cols: 11;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 40px 1fr var(--actions-w);
  grid-template-rows: var(--phrase-h) 1fr 28px;
  grid-template-areas:
    "menu phrase next"
    "board board actions"
    "status status status";
  height: 100%;
  width: 100%;
}

.top {
  grid-column: 1 / 3;
  grid-row: 1;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: stretch;
  min-height: 0;
}
#btn-menu { grid-area: auto; }
.phrase-col {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
#btn-next { grid-column: 3; }

.icon-btn {
  border: 0;
  background: transparent;
  color: #888;
  font-size: 28px;
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.25; cursor: default; }

.phrase {
  flex: 1;
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  margin: 8px 4px 4px;
  overflow-x: auto;
  align-items: stretch;
  background: #f3f7f8;
  border: 1px dashed #8aabb3;
  border-radius: 6px;
  min-height: 0;
}
.output {
  flex: 0 0 auto;
  margin: 0 4px 8px;
  padding: 6px 12px;
  background: #1b5e20;
  color: #fff;
  border-radius: 6px;
  display: flex;
  gap: 10px;
  align-items: baseline;
  min-height: 3.2vh;
}
.output[hidden] { display: none !important; }
.output-k {
  font-size: 1.2vh;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.85;
  flex: 0 0 auto;
}
#output-text {
  font-size: clamp(16px, 2.4vh, 28px);
  font-weight: 700;
  line-height: 1.2;
}
.chip {
  flex: 0 0 calc((100% - 36px) / 10);
  min-width: 64px;
  max-width: 12%;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden;
}
.chip.speaking { outline: 3px solid #d75454; }
.chip img {
  flex: 1;
  width: 100%;
  object-fit: contain;
  background: #fff;
  min-height: 0;
}
.chip .lbl {
  font-size: 1.1vh;
  text-transform: uppercase;
  text-align: center;
  padding: 2px;
  line-height: 1.1;
  background: #fff;
}

.board-wrap {
  grid-column: 1 / 3;
  grid-row: 2;
  min-height: 0;
  padding: 4px 8px 4px 4px;
}
.board {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: var(--gap);
}
.cell {
  background: #fff;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  user-select: none;
}
.cell.empty {
  background: transparent;
  cursor: default;
  pointer-events: none;
}
.cell .lbl {
  font-size: clamp(8px, 1.1vh, 13px);
  text-transform: uppercase;
  text-align: center;
  padding: 2px 3px 0;
  line-height: 1.15;
  background: #fff;
  flex: 0 0 auto;
}
.cell img {
  flex: 1;
  width: 100%;
  object-fit: contain;
  background: #fff;
  min-height: 0;
  padding: 2px;
}
.cell.folder::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 14px;
  height: 10px;
  background: linear-gradient(#f4d35e, #eea302);
  border-radius: 0 2px 2px 0;
  box-shadow: -4px 2px 0 #c98400;
}
.app.hide-labels .cell .lbl,
.app.hide-labels .chip .lbl { display: none; }

.actions {
  grid-column: 3;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 6px 8px 0;
}
.action {
  flex: 1;
  border: 0;
  border-radius: 6px;
  background: var(--btn);
  color: var(--btn-text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 1.5vh;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.action svg { width: 28px; height: 28px; }
.action.toggle[aria-pressed="false"] { background: #9aa7ab; }
.action.toggle small { font-size: 1.1vh; font-weight: 500; text-transform: none; }

.status {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 0 10px;
  font-size: 12px;
  color: #666;
  background: #d3e0e4;
}
#spoken { color: #1b5e20; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.text-btn {
  border: 0;
  background: transparent;
  color: #666;
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
}
.text-btn:disabled { opacity: 0.3; cursor: default; }

.dlg {
  border: 0;
  border-radius: 10px;
  padding: 20px 22px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg h2 { margin: 0 0 8px; font-size: 18px; }
.dlg p { margin: 0 0 12px; font-size: 14px; line-height: 1.4; }
.dlg input[type="text"] {
  width: 100%;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
}
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.dlg-actions button {
  border: 0;
  background: var(--btn);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.dlg-actions button[value="cancel"] { background: #888; }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0; font-size: 14px; }
.meta { font-size: 12px; color: #666; }

.rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 50;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 18px;
}
.phone {
  width: 100px;
  height: 56px;
  border: 3px solid #111;
  border-radius: 10px;
  animation: spin 1.6s ease-in-out infinite alternate;
}
@keyframes spin {
  from { transform: rotate(90deg); }
  to { transform: rotate(0deg); }
}

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-hint { display: flex; }
  .app { display: none; }
}
