/* Shared chrome for every emulator page.
 *
 * Every rule here styles a component that lives in COMMON_CODEBASE/js_common
 * (menu, close button, spot navigation, quest journal, performance panel), so
 * it belongs with them rather than copy-pasted into each index.html - which is
 * how pdp1 ended up with no spot-navigation styling and only pdp8 had the
 * quest journal, despite both components being shared code.
 *
 * Linked from www/public/emulator.css, a symlink back to this file. */

body {
    margin: 0;
    width: 100vw;
    height: 100vh;
}

/* Shared HUD tokens: black translucent chips, white hairlines, monospace. */
:root {
    --ui-bg: rgba(0, 0, 0, 0.82);
    --ui-bg-hover: rgba(255, 255, 255, 0.12);
    --ui-bg-active: rgba(255, 255, 255, 0.22);
    --ui-line: rgba(255, 255, 255, 0.85);
    --ui-line-soft: rgba(255, 255, 255, 0.22);
    --ui-text: #fff;
    --ui-muted: rgba(255, 255, 255, 0.6);
    --ui-font: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
}

/* Stroke icons (MenuHandler.js ICONS and the index.html buttons). */
.ui_icon {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: square;
    stroke-linejoin: miter;
    flex-shrink: 0;
}

/* Top-right control column: settings on top, context-exit under it. Both wear
 * the same chrome as the rest of the HUD (menu, spot nav, perf panel) so they
 * read as one set, and the dark chip keeps the white glyph legible whatever the
 * scene behind it happens to be. */
#close_button,
#open_settings_btn {
    position: absolute;
    right: 15px;
    width: 44px;
    height: 44px;
    box-sizing: border-box;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--ui-bg);
    border: 1px solid var(--ui-line);
    color: var(--ui-text);
    z-index: 100;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.12s ease;
}

#close_button:hover,
#open_settings_btn:hover {
    background-color: var(--ui-bg-hover);
}

#close_button:active,
#open_settings_btn:active {
    background-color: var(--ui-bg-active);
}

#close_button:focus-visible,
#open_settings_btn:focus-visible {
    outline: 2px solid var(--ui-text);
    outline-offset: 2px;
}

/* Legacy filled glyphs, for any page still carrying the old markup. */
#close_button svg:not(.ui_icon),
#open_settings_btn svg:not(.ui_icon) {
    width: 22px;
    height: 22px;
    fill: #fff;
}

#close_button {
    top: 67px;
    /* show_close_button() sets display:flex when a context wants it. */
    display: none;
}

#load_disk_container {
    position: absolute;
    left: 10px;
    top: 10px;
    z-index: 100;
    font-family: monospace;
}

#load_disk_btn {
    background: rgba(0, 0, 0, 0.7);
    color: #0f0;
    border: 1px solid #0f0;
    padding: 5px 10px;
    cursor: pointer;
    font-family: inherit;
}


#load_disk_btn:hover {
    background: rgba(0, 50, 0, 0.7);
}

#open_settings_btn {
    top: 15px;
}

/* ---------------------------------------------------------------- menu */

#menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.55);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    font-family: var(--ui-font);
}

#menu_block {
    display: flex;
    flex-direction: column;
    background-color: var(--ui-bg);
    /* Fixed size whatever the submenu holds; long lists scroll inside
     * #menu_content instead of growing the panel. */
    width: min(760px, calc(100vw - 32px));
    height: min(680px, calc(100vh - 32px));
    border: 1px solid var(--ui-line);
    color: var(--ui-text);
}

#menu_top_bar {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--ui-line);
    flex-shrink: 0;
    min-height: 72px;
}

#menu_title_wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 8px 0;
    min-width: 0;
}

#menu_breadcrumb {
    font-size: 13px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ui-muted);
}

#menu_title {
    font-size: 21px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.menu_icon_btn {
    width: 72px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--ui-text);
    cursor: pointer;
    padding: 0;
}

.menu_icon_btn .ui_icon {
    width: 26px;
    height: 26px;
}

#menu_back_btn {
    border-right: 1px solid var(--ui-line);
}

#menu_close_btn {
    border-left: 1px solid var(--ui-line);
}

.menu_icon_btn:hover {
    background-color: var(--ui-bg-hover);
}

.menu_icon_btn:active {
    background-color: var(--ui-bg-active);
}

#menu_content {
    flex: 1;
    min-height: 0;
    overscroll-behavior: contain;
    overflow-y: auto;
    width: 100%;
    scrollbar-width: thin;
    scrollbar-color: var(--ui-line) transparent;
}

#menu_content::-webkit-scrollbar {
    width: 8px;
}

#menu_content::-webkit-scrollbar-track {
    background: transparent;
}

#menu_content::-webkit-scrollbar-thumb {
    background: var(--ui-line-soft);
}

#menu_content::-webkit-scrollbar-thumb:hover {
    background: var(--ui-line);
}

.menu_item {
    box-sizing: border-box;
    width: 100%;
    min-height: 76px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    border: none;
    border-bottom: 1px solid var(--ui-line-soft);
    background: none;
    color: var(--ui-text);
    font-family: var(--ui-font);
    text-align: left;
    flex-shrink: 0;
}

.menu_item_title {
    flex: 1;
    font-size: 20px;
    letter-spacing: 0.04em;
    min-width: 0;
}

/* Rows that navigate or act. */
.menu_item_nav {
    cursor: pointer;
    position: relative;
    transition: background-color 0.12s ease;
}

.menu_item_nav:hover {
    background-color: var(--ui-bg-hover);
}

.menu_item_nav:active {
    background-color: var(--ui-bg-active);
}

/* Hairline marker on the hovered or focused row. */
.menu_item_nav::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--ui-text);
    opacity: 0;
    transition: opacity 0.12s ease;
}

.menu_item_nav:hover::before,
.menu_item_nav:focus-visible::before {
    opacity: 1;
}

.menu_item_icon {
    width: 22px;
    height: 22px;
    color: var(--ui-muted);
    transition: transform 0.12s ease, color 0.12s ease;
}

/* What the row is: before its title (MenuOption's `icon`). */
.menu_item_lead {
    width: 24px;
    height: 24px;
    color: var(--ui-muted);
    transition: color 0.12s ease;
}

.menu_item_nav:hover .menu_item_lead {
    color: var(--ui-text);
}

.menu_item_nav:hover .menu_item_icon {
    color: var(--ui-text);
    transform: translateX(3px);
}

.menu_item:focus-visible,
.menu_icon_btn:focus-visible {
    outline: 2px solid var(--ui-text);
    outline-offset: -4px;
}

.menu_empty {
    padding: 28px;
    color: var(--ui-muted);
    font-size: 18px;
}

/* Text rows (Credits): title, a paragraph, a link out. */
.menu_item_info {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding-top: 18px;
    padding-bottom: 18px;
}

.menu_item_info .menu_item_title {
    font-size: 18px;
}

.menu_item_detail {
    color: var(--ui-muted);
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-line;
}

.menu_item_link,
#book_source_link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ui-text);
    font-family: var(--ui-font);
    font-size: 15px;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.menu_item_link:hover {
    color: var(--ui-muted);
}

.menu_link_icon {
    width: 16px;
    height: 16px;
}

/* While a book is read: where its scan came from, left of the close button. */
#book_source_link {
    position: absolute;
    top: 67px;
    right: 67px;
    height: 44px;
    box-sizing: border-box;
    padding: 0 14px;
    background-color: var(--ui-bg);
    border: 1px solid var(--ui-line);
    text-decoration: none;
    z-index: 100;
    transition: background-color 0.12s ease;
}

#book_source_link:hover {
    background-color: var(--ui-bg-hover);
}

#book_source_link:focus-visible {
    outline: 2px solid var(--ui-text);
    outline-offset: 2px;
}

/* Setting rows. */
.menu_item_control {
    cursor: default;
}

.menu_item_control label {
    cursor: pointer;
}

.menu_item_control:not(.menu_item_toggle) {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 10px;
    padding-top: 18px;
    padding-bottom: 20px;
}

.menu_item_toggle {
    cursor: pointer;
}

.menu_control_row {
    display: flex;
    align-items: baseline;
    gap: 16px;
}

.menu_slider_value {
    font-size: 18px;
    color: var(--ui-muted);
    min-width: 3ch;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Range: a 2px hairline track, filled to --fill, with a square thumb. */
.menu_slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 32px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}

.menu_slider::-webkit-slider-runnable-track {
    height: 2px;
    background: linear-gradient(to right, var(--ui-text) var(--fill, 0%), var(--ui-line-soft) var(--fill, 0%));
}

.menu_slider::-moz-range-track {
    height: 2px;
    background: var(--ui-line-soft);
}

.menu_slider::-moz-range-progress {
    height: 2px;
    background: var(--ui-text);
}

.menu_slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    margin-top: -8px;
    background: #000;
    border: 2px solid var(--ui-text);
    border-radius: 0;
}

.menu_slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #000;
    border: 2px solid var(--ui-text);
    border-radius: 0;
}

.menu_slider:hover::-webkit-slider-thumb,
.menu_slider:focus-visible::-webkit-slider-thumb {
    background: var(--ui-text);
}

.menu_slider:hover::-moz-range-thumb,
.menu_slider:focus-visible::-moz-range-thumb {
    background: var(--ui-text);
}

.menu_slider:focus-visible {
    outline: 2px solid var(--ui-text);
    outline-offset: 4px;
}

/* Checkbox drawn as a square on/off switch. */
.menu_toggle {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    width: 56px;
    height: 30px;
    margin: 0;
    flex-shrink: 0;
    border: 1px solid var(--ui-line);
    background: transparent;
    cursor: pointer;
    transition: background-color 0.12s ease;
}

.menu_toggle::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: var(--ui-muted);
    transition: left 0.12s ease, background-color 0.12s ease;
}

.menu_toggle:checked {
    background: var(--ui-bg-active);
}

.menu_toggle:checked::after {
    left: 29px;
    background: var(--ui-text);
}

.menu_toggle:focus-visible {
    outline: 2px solid var(--ui-text);
    outline-offset: 3px;
}

/* ----------------------------------------------------------- inventory */

#inventory_overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    font-family: var(--ui-font);
}

#inventory_block {
    display: flex;
    flex-direction: column;
    width: min(520px, calc(100vw - 32px));
    max-height: min(560px, calc(100vh - 32px));
    background-color: var(--ui-bg);
    border: 1px solid var(--ui-line);
    color: var(--ui-text);
}

.inv_header {
    display: flex;
    align-items: stretch;
    min-height: 64px;
    border-bottom: 1px solid var(--ui-line);
    flex-shrink: 0;
}

#inventory_title {
    flex: 1;
    display: flex;
    align-items: center;
    padding-left: 24px;
    font-size: 19px;
    letter-spacing: 0.18em;
}

.inv_count {
    display: flex;
    align-items: center;
    padding: 0 18px;
    font-size: 14px;
    color: var(--ui-muted);
    font-variant-numeric: tabular-nums;
}

.inv_close {
    width: 64px;
    border-left: 1px solid var(--ui-line);
}

.inv_close .ui_icon {
    width: 24px;
    height: 24px;
}

.inv_list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--ui-line) transparent;
}

.inv_section {
    padding: 16px 24px 6px;
    font-size: 12px;
    letter-spacing: 0.16em;
    color: var(--ui-muted);
}

.inv_row {
    min-height: 64px;
    padding: 0 20px 0 24px;
}

.inv_icon {
    width: 24px;
    height: 24px;
    color: var(--ui-muted);
}

.inv_held .inv_icon,
.inv_row:hover .inv_icon {
    color: var(--ui-text);
}

.inv_action {
    flex-shrink: 0;
    padding: 5px 10px;
    border: 1px solid var(--ui-line-soft);
    font-size: 13px;
    letter-spacing: 0.12em;
    color: var(--ui-muted);
    transition: border-color 0.12s ease, color 0.12s ease;
}

.inv_row:hover .inv_action,
.inv_row:focus-visible .inv_action {
    border-color: var(--ui-text);
    color: var(--ui-text);
}

.inv_footer {
    flex-shrink: 0;
    padding: 12px 24px;
    border-top: 1px solid var(--ui-line-soft);
    font-size: 13px;
    color: var(--ui-muted);
}

@media (prefers-reduced-motion: reduce) {
    .menu_item_icon,
    .menu_toggle::after {
        transition: none;
    }
}

#quest_journal {
    position: absolute;
    left: 20px;
    bottom: 20px;
    width: 320px;
    height: 320px;
    background-color: #fff2b2;
    box-shadow: 2px 4px 10px rgba(0,0,0,0.5);
    padding: 20px;
    padding-top: 35px;
    font-family: 'Special Elite', monospace;
    color: #333;
    z-index: 100;
    /* Scribbled paper look */
    border-radius: 2px 255px 3px 25px / 255px 5px 225px 3px;
    border: 1px solid #d9cc8c;
    transform: rotate(-1.5deg);
    display: none;
    pointer-events: auto;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #d9cc8c transparent;
}

#quest_journal::-webkit-scrollbar {
    width: 8px;
}
#quest_journal::-webkit-scrollbar-thumb {
    background-color: #d9cc8c;
    border-radius: 4px;
}

#quest_drag_handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 30px;
    cursor: grab;
    background: rgba(0,0,0,0.05);
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

#quest_drag_handle:active {
    cursor: grabbing;
}

#quest_close_btn {
    position: absolute;
    top: 5px;
    right: 15px;
    cursor: pointer;
    font-size: 16px;
    font-family: sans-serif;
    font-weight: bold;
    color: #666;
    z-index: 101;
}

#quest_close_btn:hover {
    color: #000;
}

#quest_journal h3 {
    margin-top: 0;
    text-decoration: underline;
    font-size: 22px;
}

#quest_journal_steps {
    list-style-type: none;
    padding-left: 0;
}

.quest_step {
    margin-bottom: 10px;
    font-size: 18px;
}

.quest_step_desc {
    font-size: 14px;
    color: #555;
    margin-left: 20px;
    margin-top: 5px;
    display: none;
}

.quest_step.active .quest_step_desc {
    display: block;
}

.quest_step.completed {
    text-decoration: line-through;
    opacity: 0.6;
}

.quest_step.active {
    font-weight: bold;
}

/* Spot Navigation UI */
#spot_nav_overlay {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background-color: rgba(0, 0, 0, 0.8);
    border: 1px inset #fff;
    color: #fff;
    font-family: monospace;
    font-size: 14px;
    user-select: none;
    z-index: 1001;
}

.spot_nav_btn {
    background: rgba(0, 0, 0, 0.7);
    border: 1px inset #fff;
    color: #fff;
    font-family: monospace;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 14px;
}

.spot_nav_btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.spot_nav_tab {
    padding: 4px 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: monospace;
    font-size: 14px;
    background: transparent;
    color: #fff;
}

.spot_nav_tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
}

.spot_nav_tab.active {
    border: 1px inset #fff;
    background: rgba(255, 255, 255, 0.2);
    color: #0f0;
}

/* Performance HUD (PerformancePanel.js) */
#perf_panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 200px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    border-top: 1px inset #fff;
    border-right: 1px inset #fff;
    z-index: 1000;
    user-select: none;
    display: none;
}

.perf_panel_title {
    text-align: center;
    margin-bottom: 8px;
    font-weight: bold;
}

/* Telephone call (js_common/TelephoneHandler.js): the far end's
 * words typed out as they speak, and numbered replies. HUD chrome. */
#phone_dialogue {
    position: absolute;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%);
    width: min(620px, calc(100% - 32px));
    box-sizing: border-box;
    padding: 14px 18px 16px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-line);
    color: var(--ui-text);
    font-family: var(--ui-font);
    font-size: 13px;
    z-index: 100;
    display: none;
}
#phone_dialogue.open { display: block; }
#phone_dialogue .phone_speaker {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ui-muted);
}
#phone_dialogue .phone_status { margin-top: 8px; color: var(--ui-muted); }
#phone_dialogue .phone_status:empty { display: none; }
#phone_dialogue .phone_line {
    margin: 8px 0 0;
    min-height: 2.6em;
    font-family: 'Special Elite', monospace;
    font-size: 17px;
    line-height: 1.35;
}
#phone_dialogue .phone_replies { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
#phone_dialogue .phone_replies:empty { display: none; }
#phone_dialogue .phone_reply {
    display: flex;
    align-items: baseline;
    gap: 10px;
    width: 100%;
    padding: 7px 10px;
    background: transparent;
    border: 1px solid var(--ui-line-soft);
    color: var(--ui-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
#phone_dialogue .phone_reply:hover,
#phone_dialogue .phone_reply:focus-visible { background: var(--ui-bg-hover); border-color: var(--ui-line); outline: none; }
#phone_dialogue .phone_key { color: var(--ui-muted); }
