#companion {
  position: fixed;
  right: 28px;
  top: 28px;
  width: 210px;
  padding: 18px 20px;
  background: #faf4e6ed;
  border: 1px solid #d9cba8;
  border-radius: 16px;
  color: #254b41;
  box-shadow: 0 9px 35px #193c3512;
  font-family: Georgia, serif;
}
#companion strong {
  display: block;
  font-size: 21px;
}
#companion span,
#companion small {
  display: block;
  margin-top: 7px;
  font: 12px system-ui;
  color: #65766b;
}
.xp-track {
  height: 7px;
  margin: 10px 0;
  background: #e2decb;
  border-radius: 10px;
  overflow: hidden;
}
#xp-fill {
  display: block;
  height: 100%;
  background: #b79445;
  transition: width 0.6s;
}
#companion details {
  margin-top: 12px;
  font-size: 14px;
}
#companion summary {
  cursor: pointer;
}
#companion button {
  display: block;
  width: 100%;
  border: 1px solid #d5c9a9;
  background: #fffaf0;
  color: #254b41;
  border-radius: 7px;
  padding: 9px;
  margin-top: 7px;
  text-align: left;
  cursor: pointer;
}
#companion button:disabled {
  opacity: 0.4;
  cursor: default;
}
#dragon-message {
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 0;
}
#meters {
  position: fixed;
  left: 50%;
  top: 28px;
  transform: translateX(-50%);
  display: flex;
  gap: 22px;
  padding: 13px 24px;
  border: 1px solid #d9cba8;
  background: #faf4e6ed;
  border-radius: 30px;
  font: 12px system-ui;
  color: #40574c;
}
#meters[hidden] {
  display: none;
}
#meters span {
  display: grid;
  grid-template-columns: 9px auto;
  gap: 4px 7px;
}
#meters i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 3px;
}
#meters b {
  grid-column: 2;
  font: 18px Georgia;
}
#home {
  right: 300px;
}
#hint {
  max-width: 420px;
  font-size: 14px;
}
#scene:focus-visible {
  outline: 2px solid #b79445;
  outline-offset: -3px;
}
@media (max-width: 800px) {
  #companion {
    top: 88px;
    right: 10px;
    width: 145px;
    padding: 12px;
  }
  #companion strong {
    font-size: 17px;
  }
  #meters {
    top: 12px;
    gap: 9px;
    padding: 10px;
    left: 60%;
    white-space: nowrap;
  }
  #home {
    right: 12px;
    top: auto;
    bottom: 95px;
  }
  #hint {
    display: none;
  }
  header {
    font-size: 20px;
  }
}

.nell-portrait {
  width: 64px;
  height: 68px;
  object-fit: contain;
  float: right;
  margin: -7px -9px 0 7px;
}
#companion strong {
  font-size: 19px;
}
#companion {
  width: 222px;
}
#companion .xp-track {
  clear: both;
}
#meters {
  box-shadow: 0 6px 25px #4739190a;
}

.nell-portrait {
  width: 50px;
  height: 54px;
  margin: 0 0 5px 7px;
}
#companion strong {
  font-size: 17px;
  white-space: nowrap;
}
#hint {
  right: auto;
  left: 24px;
  bottom: 24px;
  max-width: 330px;
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
}

#mass-controls {
  position: fixed;
  top: 110px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 22px;
  background: #faf4e6ed;
  border: 1px solid #d9cba8;
  display: flex;
  align-items: center;
  gap: 10px;
  font: 12px system-ui;
  color: #40574c;
}
#mass-controls[hidden] {
  display: none;
}
#mass-controls button {
  border: 1px solid #cbbd9c;
  border-radius: 15px;
  padding: 7px 12px;
  background: #fffaf0;
  color: #29483f;
  cursor: pointer;
}
#mass-controls button[aria-pressed="true"] {
  background: #29483f;
  color: #fffaf0;
}

/* Navigation belongs to the paper; keyboard controls remain available. */
#dock,
#home,
#hint {
  display: none !important;
}
header {
  opacity: 0.65;
  font-size: 18px;
}
#companion {
  top: 18px;
  right: 18px;
  transform: scale(0.86);
  transform-origin: top right;
  background: #f9f4e8df;
  box-shadow: none;
  border-radius: 8px;
}
#mass-controls {
  top: auto;
  bottom: 18px;
}
#reader {
  display: none;
}
@media (max-width: 800px) {
  #reader {
    display: block;
  }
  #companion {
    transform: scale(0.72);
  }
}

#mass-controls {
  display: none !important;
}

/* A quiet companion: identity and earned progress only. */
#companion {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  width: 210px;
  padding: 12px 16px;
}
#companion .nell-portrait {
  grid-column: 2;
  grid-row: 1;
  width: 44px;
  height: 44px;
  float: none;
  margin: 0;
}
#companion strong {
  grid-column: 1;
  grid-row: 1;
  font-size: 16px;
}
#companion .xp-track {
  grid-column: 1 / -1;
  margin: 0;
  width: 100%;
  background: #d5dbe1;
}

/* Portrait keeps the paper world large and its words in an accessible reading sheet. */
@media (max-width: 650px) {
  #companion {
    top: 8px;
    right: 8px;
    width: 176px;
    transform: none;
    padding: 8px 12px;
    gap: 5px;
  }
  #companion .nell-portrait {
    width: 30px;
    height: 30px;
  }
  #companion strong {
    font-size: 14px;
  }
  #reader {
    display: block;
    top: 58%;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 0;
    width: 100%;
    max-width: none;
    border-radius: 22px 22px 0 0;
    background: #fcf8ef;
    box-shadow: 0 -8px 30px #253c3515;
  }
  #handle {
    padding: 12px 20px 6px;
    font-size: 18px;
  }
  #reading,
  #reader.expanded #reading {
    display: block;
    max-height: calc(42dvh - 112px - env(safe-area-inset-bottom));
    padding: 0 20px 16px;
    overflow-y: auto;
    font-size: 18px;
    line-height: 1.45;
  }
  #heading,
  #eyebrow,
  #chevron,
  #reader .grip {
    display: none;
  }
  #explain {
    margin: 8px 0;
  }
  #notation {
    margin: 8px 0;
    color: #a43f30;
    font-size: 24px;
  }
  #task {
    margin: 10px 0;
    font-size: 18px;
  }
  #choices button {
    min-width: 54px;
    min-height: 48px;
    border-radius: 12px;
    background: #e8eee9;
    color: #183f35;
    font:
      20px Georgia,
      serif;
  }
  #feedback:empty {
    display: none;
  }
  #dock:not([hidden]) {
    display: flex !important;
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100%;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    padding: 6px 14px calc(6px + env(safe-area-inset-bottom));
    gap: 8px;
    background: #fcf8ef;
  }
  #dock > div {
    display: none;
  }
  #dock button {
    flex: 1;
    width: auto;
    min-height: 44px;
  }
  #view {
    display: none;
  }
  #reader.expanded {
    top: 40%;
  }
  #reader.expanded #reading {
    max-height: calc(60dvh - 112px - env(safe-area-inset-bottom));
  }
  #celebrate {
    top: 22%;
  }
}

@media (max-width: 650px) {
  #companion {
    width: 118px;
    grid-template-columns: 1fr;
    padding: 8px 10px;
  }
  #companion .nell-portrait {
    display: none;
  }
  #companion strong {
    font-size: 13px;
  }
  .library-tools {
    left: 10px;
    top: 12px;
    gap: 4px;
  }
  .library-tools a {
    font-size: 16px;
  }
  .library-tools button {
    padding: 8px;
    font-size: 11px;
  }
}

@media (max-width: 380px) {
  #companion {
    width: 108px;
  }
}

/* Voice remains visible before the cover opens, independently of page navigation. */
.book-voice-control {
  position:fixed;
  z-index:25;
  top:20px;
  left:50%;
  transform:translateX(-50%);
  display:grid;
  justify-items:center;
  gap:5px;
  max-width:calc(100vw - 24px);
  color:#29483f;
}
.book-voice-control #listen {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:134px;
  min-height:44px;
  padding:10px 18px;
  border:1px solid #b8ac9238;
  border-radius:99px;
  background:#fff9ebed;
  color:#29483f;
  box-shadow:0 4px 16px #193c3510;
  font:500 13px/1.35 system-ui,sans-serif;
  cursor:pointer;
}
.book-voice-control #listen::before { content:"♪";margin-right:9px;color:#8b613e;font-size:17px; }
.book-voice-control #listen:focus-visible { outline:3px solid #8b613e;outline-offset:3px; }
#voice-status { max-width:26ch;font:11px/1.4 system-ui,sans-serif;text-align:center;background:#fff9ebed;border-radius:6px; }
#voice-status:empty { display:none; }
@media (max-width:650px) {
  .book-voice-control { top:56px;left:12px;transform:none;justify-items:start;max-width:190px; }
  .book-voice-control #listen { min-width:130px;padding:10px 14px; }
  #voice-status { text-align:left; }
}
