/* The controller follows the same brass-and-ink focus language as the book. */
body[data-input-mode="gamepad"] .controller-focused {
  outline: 3px solid var(--gold, #ffd66b) !important; outline-offset: 4px;
  box-shadow: 0 0 0 6px rgba(18, 19, 48, .9), 0 5px 16px rgba(0, 0, 0, .3) !important;
}
.controller-action-hint, .controller-guide { display: none; }
body[data-input-mode="gamepad"] .controller-action-hint { display: inline; font-size: .8em; opacity: .8; }
body[data-input-mode="gamepad"] .controller-guide { display: block; margin-top: 8px; font-size: 12px; line-height: 1.4; color: var(--cream, #fff4db); }
.controller-status {
  position: fixed; right: 10px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 1100;
  max-width: min(460px, calc(100vw - 20px)); padding: 6px 12px; border: 1px solid #b8a273;
  border-radius: 14px; background: #202045; color: #fff2d5; font-size: 12px; line-height: 1.35;
  pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.controller-keyboard, .controller-options, .title-controls {
  color: var(--cream, #fff4db); background: #1d1d43; border: 2px solid #c5ae7c;
  border-radius: 20px; box-shadow: 0 20px 80px rgba(0,0,0,.5); padding: 0;
}
.controller-keyboard { width: min(720px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); margin: auto; overflow: auto; }
.controller-keyboard::backdrop { background: rgba(10, 10, 30, .8); backdrop-filter: blur(3px); }
.ck-book { padding: 20px; }
.ck-book h2 { color: var(--gold, #ffd66b); font-size: 22px; margin: 0 0 12px; }
.ck-draft { display: block; width: 100%; font: inherit; font-size: 20px; color: #3a3024; background: #fff4dc; border: 2px solid #b6a178; border-radius: 10px; padding: 10px 12px; min-height: 46px; }
textarea.ck-draft { min-height: 80px; resize: vertical; }
.ck-help { font-size: 13px; line-height: 1.4; opacity: .9; margin: 10px 0 14px; }
.ck-keys { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; }
.ck-book button, .controller-option, .controller-options-cancel {
  color: #fff2d5; background: linear-gradient(#44446e, #2f3056); border: 1px solid #b8a273;
  border-radius: 9px; font: inherit; font-weight: 800; min-height: 44px; padding: 7px 8px; cursor: pointer;
}
.ck-key { font-size: 20px !important; }
.ck-book button:hover, .controller-option:hover { background: #57557a; }
.ck-book button:focus-visible, .ck-draft:focus-visible, .controller-option:focus-visible, .controller-options-cancel:focus-visible { outline: 3px solid #ffd66b; outline-offset: 2px; }
.ck-book button[aria-pressed="true"] { background: #655a76; border-color: #ffe5a2; }
.ck-tools { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.ck-tools button { flex: 1 1 auto; }
.ck-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(255,214,107,.25); }
.ck-footer button { min-width: 110px; }
#ck-done { background: linear-gradient(#ffe6a3, #e5bc68); color: #453321; }
.controller-options { position: fixed; inset: 0; margin: auto; width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 18px; z-index: 1100; }
.controller-options::backdrop { background: rgba(10, 10, 30, .45); }
.controller-options-title { color: #ffd66b; margin: 0 0 12px; }
.controller-option { display: block; width: 100%; margin-bottom: 8px; text-align: left; }
.title-controls { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); margin: auto; padding: 20px; }
.title-controls::backdrop { background: rgba(10,10,30,.75); }
.title-controls h2 { color: #ffd66b; margin: 0 0 14px; }
#title-settings-rows { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
#title-settings-rows button { min-height: 44px; width: 100%; text-align: left; }
#title-settings-rows .val { float: right; color: #ffd66b; }
#title-volume { display: block; width: 100%; min-height: 44px; margin: 0 0 14px; accent-color: #ffd66b; }
#title-settings-close { width: 100%; min-height: 46px; padding: 10px 18px; border: 1px solid #e2c37e; border-radius: 12px; background: linear-gradient(#ffe6a3, #e5bc68); color: #453321; font-size: 16px; font-weight: 800; }
@media (max-width: 560px) {
  .ck-book { padding: 12px; }
  .ck-book h2 { font-size: 18px; }
  .ck-draft { font-size: 18px; }
  .ck-keys { gap: 4px; grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .ck-key { font-size: 18px !important; padding: 4px !important; }
  .ck-help { font-size: 12px; margin: 8px 0; }
  .ck-tools { gap: 5px; }
  .ck-tools button { font-size: 13px; }
  .ck-footer { margin-top: 10px; padding-top: 10px; }
  .controller-status { font-size: 11px; padding: 4px 8px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .ck-book { padding: 12px; }
  .ck-book h2 { font-size: 18px; margin-bottom: 6px; }
  .ck-help { display: none; }
  .ck-keys { grid-template-columns: repeat(12, minmax(0, 1fr)); margin-top: 8px; }
  .ck-tools { margin-top: 8px; }
  .ck-footer { margin-top: 8px; padding-top: 8px; }
}
/* The short phone keeps finishing controls in view by omitting the explanatory
   paragraph; the named keys and Done/Cancel retain their ordinary semantics. */
@media (max-width: 380px) and (max-height: 700px) and (orientation: portrait) { .ck-help { display: none; } }
@media (prefers-reduced-motion: reduce) { .controller-focused, .controller-keyboard, .controller-options { transition: none !important; animation: none !important; } }
