/* Layout on top of 98.css: a full-viewport application frame with movable windows inside. */

:root {
    --desktop: #008080;
    --surface: #c0c0c0;
    --grid-line: #d4d0c8;
    --selection: #000080;
}

html {
    background: var(--desktop);
}

body {
    margin: 0;
}

/* Without scripts, or when the editor cannot start, the page is its plain "About" text. */
html:not(.js) body {
    display: flex;
    justify-content: center;
    padding: 16px 8px;
}

html:not(.js) jsee-app,
html.js .plain-page {
    display: none;
}

/* With scripts the application owns the viewport from the first paint: only the workspace and the windows
   scroll, never the page. */
html.js,
html.js body {
    height: 100%;
    overflow: hidden;
}

jsee-app {
    display: block;
    height: 100%;
}

.menubar-placeholder {
    height: 23px;
}

jsee-character,
jsee-tabs {
    display: block;
}

[hidden] {
    display: none !important;
}

/* A scrollbar has one arrow at each end. Depending on the system's settings the browser also offers a second
   one next to it (down beside up, up beside down): those are never wanted here. */
::-webkit-scrollbar-button:vertical:start:increment,
::-webkit-scrollbar-button:vertical:end:decrement,
::-webkit-scrollbar-button:horizontal:start:increment,
::-webkit-scrollbar-button:horizontal:end:decrement {
    display: none;
}

/* --- Application frame --- */

.title-bar {
    position: relative;
}

.title-bar-text {
    padding-left: 22px;
}

.logo {
    position: absolute;
    top: 0;
    left: 2px;
    width: 20px;
    height: 20px;
    background: url("/favicon.png") center / 20px 20px;
}

.window-body {
    margin: 0;
}

.outer-window {
    display: flex;
    box-sizing: border-box;
    flex-direction: column;
    height: 100%;
}

.app-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.sunken {
    padding: 2px;
    box-shadow: inset -1px -1px #fff, inset 1px 1px grey, inset -2px -2px #dfdfdf, inset 2px 2px #0a0a0a;
}

.workspace {
    position: relative;
    flex: 1;
    overflow: auto;
    background: #808080;
}

.status {
    min-height: 23px;
    padding-left: 4px;
    line-height: 23px;
}

/* --- Menu bar and toolbar --- */

jsee-menubar {
    display: flex;
    padding-left: 4px;
}

.menu {
    position: relative;
}

.menu-button {
    min-width: 0;
    padding: 0 5px;
    box-shadow: none;
}

.menu-button[aria-expanded="true"] {
    background: var(--selection);
    color: #fff;
}

.menu-popup {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 100000;
    min-width: 170px;
    margin: 0;
    padding: 2px;
    background: var(--surface);
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #dfdfdf, inset -2px -2px grey, inset 2px 2px #fff;
    list-style: none;
}

.menu-popup button {
    display: block;
    width: 100%;
    min-height: 0;
    padding: 3px 20px 3px 22px;
    background: none;
    box-shadow: none;
    text-align: left;
    white-space: nowrap;
}

.menu-popup button:not(:disabled):is(:hover, :focus-visible) {
    background: var(--selection);
    color: #fff;
    outline: none;
}

.menu-popup button.checked::before {
    position: absolute;
    left: 8px;
    content: "\2713";
}

.menu-separator {
    height: 2px;
    margin: 3px 1px;
    border-top: 1px solid grey;
    border-bottom: 1px solid #fff;
}

.toolbar-separator {
    height: 5px;
    box-shadow: inset -1px -1px #fff, inset 0 1px grey, inset 1px -2px grey, inset 2px 2px #fff;
    clip-path: inset(0 2px 2px 2px);
}

.icons-toolbar {
    display: flex;
    gap: 2px;
    height: 21px;
    padding-left: 4px;
}

.icons-toolbar > button {
    width: 23px;
    min-width: 0;
    height: 24px;
    margin-top: -3px;
    padding: 0;
    background: center / contain no-repeat;
    box-shadow: none;
}

.icons-toolbar > button:disabled {
    opacity: 0.5;
}

.icons-toolbar > .open-button {
    background-image: url("/open.png");
}

.icons-toolbar > .save-button {
    background-image: url("/save.png");
}

/* --- Windows of the workspace --- */

.mdi-window {
    position: absolute;
    display: flex;
    box-sizing: border-box;
    flex-direction: column;
}

.mdi-window:not([active]) > .title-bar {
    background: linear-gradient(90deg, #808080, #b5b5b5);
}

.mdi-window > .title-bar {
    flex: none;
    cursor: default;
    touch-action: none;
    user-select: none;
}

/* A window without a set height is as tall as its content. One with a height (or maximized) gives its
   content that height, and is the only thing that scrolls when the content does not fit. */
.mdi-body {
    overflow: auto;
}

.mdi-window:is([sized], [state="maximized"]) > .mdi-body {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    min-height: 0;
}

.mdi-window:is([sized], [state="maximized"]) > .mdi-body > :not(.about) {
    flex: 1 1 0;
    min-height: 0;
}

.mdi-window[state="maximized"] {
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
}

/* Minimized windows line up along the bottom of the workspace. */
.mdi-window[state="minimized"] {
    top: auto !important;
    bottom: 2px;
    left: calc(2px + var(--tray-index, 0) * 164px) !important;
    width: 160px !important;
    height: auto !important;
}

.mdi-window[state="minimized"] > :is(.mdi-body, .resize-handle),
.mdi-window[state="maximized"] > .resize-handle {
    display: none;
}

.mdi-window[state="minimized"] .title-bar-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.resize-handle {
    position: absolute;
    touch-action: none;
}

.resize-handle[data-edge="e"] {
    top: 0;
    right: -2px;
    bottom: 12px;
    width: 6px;
    cursor: ew-resize;
}

.resize-handle[data-edge="s"] {
    right: 12px;
    bottom: -2px;
    left: 0;
    height: 6px;
    cursor: ns-resize;
}

.resize-handle[data-edge="se"] {
    right: -2px;
    bottom: -2px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
}

.welcome {
    padding: 12px 14px;
    line-height: 1.5;
}

.welcome p {
    margin: 0 0 10px;
}

.welcome p:last-child {
    margin: 16px 0 4px;
    text-align: center;
}

/* The editors keep a minimum size: a smaller window scrolls them. */
.document-body {
    display: flex;
    overflow: auto;
}

.document-body > * {
    flex: 1;
    min-width: 0;
}

.game-body {
    padding: 8px;
}

/* --- Character window --- */

.character-window {
    display: flex;
    box-sizing: border-box;
    gap: 8px;
    min-width: 870px;
    height: 100%;
    /* Leaves room for a horizontal scrollbar in a window of the default height, so a narrow window does
       not grow a vertical one as well. */
    min-height: 392px;
    padding: 8px;
}

.portrait-column {
    display: flex;
    flex-direction: column;
    width: 110px;
}

.portrait {
    height: 173px;
    margin: 2px 0;
    background-size: cover;
    box-shadow: inset -1px -1px #fff, inset 1px 1px grey, inset -1px -1px #dfdfdf, inset 1px 1px #0a0a0a;
}

.character-selector {
    margin: 12px 0 0;
}

.character-selector:disabled {
    opacity: 0.5;
}

.tabs-column {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

/* --- Tabs --- */

.tabs {
    display: flex;
    align-items: flex-end;
}

.tab {
    position: relative;
    height: 10px;
    margin: 0 0 2px -2px;
    padding: 5px 8px 7px;
    border-radius: 3px 2px 0 0;
    background: silver;
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #fff, inset -2px -2px grey, inset 2px 2px #dfdfdf;
    clip-path: inset(0 0 2px 0);
    cursor: default;
    user-select: none;
}

.tab:first-child {
    margin-left: 0;
}

.tab.active {
    z-index: 1;
    height: 14px;
    margin-bottom: 0;
}

.tab:focus-visible {
    outline: 1px dotted #000;
    outline-offset: -5px;
}

.tab-contents {
    box-sizing: border-box;
    flex: 1;
    min-height: 0;
    margin-top: -4px;
    padding: 2px;
    background: silver;
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #fff, inset -2px -2px grey, inset 2px 2px #dfdfdf;
}

.tab-content {
    display: none;
    box-sizing: border-box;
    height: 100%;
    padding: 10px 10px 0 12px;
    overflow: auto; /* A panel never spills out of its box, whatever the font metrics. */
}

.tab-content.active {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

/* --- Fields --- */

/* The pixel font is not smoothed. When a box lands on a fraction of a pixel (table columns and grid tracks
   often do), the first column of its first character falls just outside the box and is cut off: a "0" reads
   as ")". Starting the text one pixel further in keeps it whole; the padding gives that pixel back. */
input[type="text"],
input[type="search"],
select {
    padding-left: 3px;
    text-indent: 1px;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(var(--columns, 1), max-content);
    gap: 6px 12px;
    align-items: center;
}

.field-grid > .field-row {
    margin: 0;
}

.field-row > label {
    min-width: 60px;
}

.field-row > label.long-label {
    min-width: 80px;
}

.field-separator {
    grid-column: 1 / -1;
    width: 100%;
    margin: 0;
    border: 0;
    border-top: 2px solid #000;
}

.shorter-input {
    width: 32px;
}

.short-input {
    width: 38px;
}

.long-input {
    width: 98px;
}

.levels > input + input {
    margin-left: 1px;
}

select:focus {
    color: #000;
    background-color: #fff;
}

fieldset {
    margin: 0;
}

.abilities-grid {
    padding-top: 0;
}

.thief-skills {
    margin-left: auto;
}

.characteristics-grid label {
    min-width: 83px;
}

.characteristics-grid select {
    min-width: 172px;
}

.saving-throws label {
    min-width: 130px;
}

.proficiencies-grid {
    column-gap: 24px;
}

.proficiencies-grid .field-row:not(.proficient) input {
    color: #808080;
}

.proficiencies-grid input + input {
    margin-left: 2px;
}

.game-tabs {
    display: flex;
    flex-direction: column;
    min-width: 500px;
    min-height: 180px;
}

/* --- Record tables --- */

jsee-records {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    height: calc(100% - 10px);
}

.records-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.records-toolbar > input {
    width: 180px;
}

.records-count {
    flex: 1;
}

.records-panel {
    flex: 1;
    min-height: 0;
}

.records-panel {
    background: var(--surface);
}

.records-panel table {
    width: 100%;
    background: #fff;
}

/* The header row stays in place while the rows scroll under it. Dropdowns are positioned boxes too, and
   would be painted over it without this. */
.records-panel thead th {
    z-index: 2;
}

/* Cells look like a grid control: flat editors separated by lines, highlighted while edited. */
.records-panel td {
    padding: 0;
    border: solid var(--grid-line);
    border-width: 0 1px 1px 0;
}

.records-panel td > input,
.records-panel td > select {
    box-sizing: border-box;
    width: 100%;
    height: 20px;
    border: 0;
    background-color: transparent;
    box-shadow: none;
}

.records-panel td > select {
    padding-right: 20px;
}

.records-panel tbody tr:nth-child(even) {
    background: #f4f2ec;
}

.records-panel tbody tr:focus-within {
    background: #fffbd6;
}

.records-panel td > input:focus,
.records-panel td > select:focus {
    outline: 1px solid var(--selection);
    outline-offset: -1px;
}

.records-panel td.record-description {
    padding: 0 6px;
    color: #404040;
}

.records-panel td:last-child {
    width: 1%;
    padding: 0 5px;
    text-align: center;
}

.record-description {
    max-width: 165px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The remove button of a row: a small square with a crisp cross, like the close button of a window. */
.record-remove {
    display: block;
    width: 16px;
    min-width: 0;
    height: 14px;
    min-height: 0;
    margin: 0 auto;
    padding: 0;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='8' height='7' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h2v1h1v1h2V1h1V0h2v1H7v1H6v1H5v1h1v1h1v1h1v1H6V6H5V5H3v1H2v1H0V6h1V5h1V4h1V3H2V2H1V1H0z' fill='%23000'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    font-size: 0; /* The cross is drawn, the "x" character is only there for readers without styles. */
}

.record-remove:active {
    background-position: calc(50% + 1px) calc(50% + 1px);
}

.record-remove:hover {
    background-color: #d8d8d8;
}

.records-note {
    margin: 0;
}

.medium-input {
    width: 56px;
}

.records-panel td > select {
    min-width: 160px;
}

.effects-table .text-input {
    width: 70px;
}

.variable-name {
    width: 300px;
}

.proficiencies-grid label {
    min-width: 125px;
}

.text-input {
    width: 80px;
}

.wide-text-input {
    width: 200px;
}

.appearance-grid select {
    width: 210px;
}

.misc-grid label {
    min-width: 100px;
}

.flag-grid {
    gap: 4px 16px;
}

.flag-grid label {
    min-width: 0;
    white-space: nowrap;
}

/* --- Dialogs --- */

dialog.window {
    padding: 3px;
    border: 0;
    color: inherit;
}

dialog.window::backdrop {
    background: rgb(0 0 0 / 30%);
}

dialog .window-body {
    margin: 8px;
}

.dialog-note {
    margin: 8px 0 0;
}

.portrait-grid {
    display: grid;
    grid-template-columns: repeat(8, max-content);
    gap: 4px;
    max-height: 380px;
    padding: 6px;
    overflow-y: auto;
    background: #404040;
}

.portrait-option {
    min-width: 0;
    min-height: 0;
    padding: 2px;
    line-height: 0;
}

.portrait-option.active {
    outline: 2px solid #ffd700;
    outline-offset: 1px;
}

/* --- About (static content, also readable without JavaScript) --- */

.about {
    box-sizing: border-box;
    width: 920px;
    max-width: 100%;
}

.mdi-body > .about {
    width: auto;
}

.startup-error {
    padding: 8px 10px;
    border: 1px solid #800000;
    background: #fff;
    color: #800000;
}

.about .window-body {
    margin: 12px 16px 16px;
    /* Long text reads better in a regular font than in the pixel font of the controls. */
    font: 13px/1.6 Tahoma, Verdana, "Segoe UI", sans-serif;
    -webkit-font-smoothing: auto;
}

.about h1 {
    margin: 0 0 8px;
    font-size: 18px;
}

.about h2 {
    margin: 18px 0 4px;
    font-size: 14px;
}

.about p,
.about ul,
.about ol,
.about dl {
    max-width: 78ch;
    margin: 0 0 8px;
}

.about li {
    margin-bottom: 2px;
}

.about dt {
    margin-top: 8px;
    font-weight: bold;
}

.about dd {
    margin: 0;
}

.about code {
    padding: 0 3px;
    background: #dfdfdf;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.site-footer {
    margin: 16px;
    padding-top: 8px;
    border-top: 1px solid grey;
    font: 12px/1.6 Tahoma, Verdana, "Segoe UI", sans-serif;
}

/* --- Inventory and spells --- */

jsee-inventory,
jsee-spells {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    height: calc(100% - 10px);
}

.records-panel th[scope="row"] {
    padding: 0 6px;
    border: solid var(--grid-line);
    border-width: 0 1px 1px 0;
    background: var(--surface);
    font-weight: normal;
    text-align: left;
    white-space: nowrap;
}

.records-panel tr.empty-slot input:disabled,
.records-panel tr.empty-slot .record-check label {
    visibility: hidden;
}

.records-panel td.record-check {
    padding: 0 8px;
    text-align: center;
}

/* A check box on its own in a cell sits in the middle of it. The library draws the box to the left of the
   text of its label; here the label has no text to show, so the box is the label. */
.records-panel td.record-check > label {
    display: inline-block;
    width: 13px;
    height: 13px;
    margin: 0;
    vertical-align: middle;
}

.records-panel td.record-check > label::before {
    top: 0;
    left: 0;
    margin: 0;
}

.records-panel td.record-check > input:checked + label::after {
    top: 3px;
    left: 3px;
}

.records-panel td.record-number {
    padding: 0 6px;
    text-align: right;
}

.records-panel td.record-stepper {
    padding: 0 4px;
    white-space: nowrap;
}

.record-stepper > button {
    min-width: 0;
    min-height: 0;
    padding: 0 6px;
}

.record-stepper > span {
    display: inline-block;
    min-width: 20px;
    text-align: center;
}

.spell-slots {
    display: flex;
    gap: 10px;
    align-items: center;
}

.spell-slots label,
.records-toolbar label {
    display: flex;
    gap: 4px;
    align-items: center;
}

.name-of {
    min-height: 14px;
    padding-left: 86px;
    color: #404040;
}

.name-references {
    align-self: flex-start;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* --- Item and spell picker --- */

.picker-dialog {
    width: min(860px, 96vw);
}

dialog .picker-body {
    display: grid;
    grid-template: "categories results preview" minmax(0, 1fr) "buttons buttons buttons" auto / 170px minmax(0, 1fr) 300px;
    gap: 8px 10px;
    height: min(520px, 76vh);
}

.picker-categories,
.picker-results,
.picker-preview {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

.picker-categories {
    grid-area: categories;
}

.picker-categories > select {
    flex: 1;
    min-height: 0;
}

.picker-results {
    grid-area: results;
}

.picker-list {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    background: #fff;
    list-style: none;
}

.picker-list > li {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 2px 6px;
    cursor: default;
    user-select: none;
}

.picker-list > li.selected {
    background: var(--selection);
    color: #fff;
}

.picker-resource {
    color: #606060;
}

li.selected > .picker-resource {
    color: #c0c0c0;
}

.picker-preview {
    grid-area: preview;
    gap: 8px;
}

.picker-heading {
    display: flex;
    gap: 10px;
    align-items: center;
}

.picker-icon > svg {
    display: block;
    width: 48px;
    height: 48px;
}

.picker-name {
    font-weight: bold;
}

.picker-details {
    flex: 1;
    min-height: 0;
    padding: 8px 10px;
    overflow-y: auto;
    background: #fff;
}

.picker-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 3px 12px;
    margin: 0;
}

.picker-facts > dt {
    color: #505050;
}

.picker-facts > dd {
    margin: 0;
}

.picker-details h3 {
    margin: 12px 0 4px;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--grid-line);
    font-size: 11px;
}

.picker-details ul {
    margin: 0;
    padding-left: 16px;
}

.picker-details li {
    margin-bottom: 2px;
}

.picker-hint {
    color: #404040;
}

.jsee-icon {
    flex: none;
    vertical-align: -3px;
}

.picker-entry-name {
    flex: 1;
}

.picker-buttons {
    display: flex;
    grid-area: buttons;
    gap: 6px;
    align-items: center;
}

.picker-buttons > input {
    width: 90px;
}

.picker-spacer {
    flex: 1;
}

.records-panel td.record-pick {
    display: flex;
    align-items: center;
}

/* The button that opens the list to choose from: a small square with three crisp dots, drawn like the cross of
   the remove button. */
.record-pick > button {
    flex: none;
    width: 18px;
    min-width: 0;
    height: 14px;
    min-height: 0;
    margin-right: 2px;
    padding: 0;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='10' height='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h2v2H0zM4 0h2v2H4zM8 0h2v2H8z' fill='%23000'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center calc(50% + 2px);
    font-size: 0; /* The dots are drawn, the "..." character is only there for readers without styles. */
    vertical-align: middle;
}

.record-pick > button:active {
    background-position: calc(50% + 1px) calc(50% + 3px);
}

.record-pick > button:hover {
    background-color: #d8d8d8;
}

/* Marks cursed items wherever they are listed. */
.item-warning {
    margin-left: 4px;
    padding: 0 4px;
    background: #800000;
    color: #fff;
    font-size: 10px;
}

li.selected .item-warning {
    background: #fff;
    color: #800000;
}
