/*
    Copyright (C) 2019 Nicolas Bertin

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

.wig-header {
  text-align: center;
}

.wig-input {
  padding: 8px 0;
  height : 16px;
}

.wig-text {
  text-align   : justify;
  overflow-wrap: break-word;
}

.wig-text-item {
  padding      : 0;
  margin       : 0;
  text-align   : left;
  white-space  : nowrap;
  overflow     : hidden;
  text-overflow: ellipsis;
}

.wig-ellipsis {
  white-space  : nowrap;
  overflow     : hidden;
  text-overflow: ellipsis;
}

.wig-warning {
  font-weight: bold;
  color      : orange;
}

.wig-btn {
  padding: 8px 0;
  box-sizing: border-box;
}

.wig-btn-small {
  height: 48px;
}

.wig-btn-large {
  height: 96px;
}

.wig-table {
  display: table;
}

.wig-row {
  display: table-row;
}

.wig-cell {
  display: table-cell;
  padding: 4px;
}

.wig-distance {
  padding-top: 0;
  padding-bottom: 0;
  /*
  margin-left   :  4px;
  line-height   : 32px;
  vertical-align: inherit;
  */
  font-size     : 2em;
}

.wig-bearing {
  /*
  margin-right: 8px;
  */
}

.wig-image {
  max-width: 256px;
}

.wig-image-container {
  text-align: center;
  overflow  : hidden;
}

.wig-spacer {
  padding-top: 16px;
}

.emulator-dialog #id-emul {
  --webwigo-panel-height: calc(100vh - 100px);
  --webwigo-panel-height: calc(100dvh - 100px);
  box-sizing: border-box;
  max-height: var(--webwigo-panel-height);
  overflow: auto;
  overscroll-behavior: contain;
}

#id-emul:has(> #id-splashscreen:not([hidden])) {
  overflow: hidden;
}

#id-splashscreen:not([hidden]) {
  display: flex;
  flex-direction: column;
  max-height: calc(var(--webwigo-panel-height) - 1em);
}

#id-splashscreen-description {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#id-splashscreen > .wig-spacer {
  flex: none;
}

.emulator-dialog .wig-image {
  max-width: 100%;
  max-height: 35vh;
  object-fit: contain;
}

.emulator-dialog .wig-input {
  box-sizing: border-box;
  min-height: 44px;
  padding: 6px 10px;
  font-size: 16px;
}

.wig-input-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.wig-input-actions label {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.wig-input-actions button {
  min-height: 28px;
}

.emulator-dialog .btn-info {
  background: #28649c;
  border-color: #235687;
}

.emulator-dialog .btn-info:hover, .emulator-dialog .btn-info:focus {
  background: #1c4b79;
}

.mobile-view-map, .mobile-player-toggle { display: none; }

@media (max-width: 700px), (max-height: 480px) and (pointer: coarse) {
  .emulator-dialog .ui-dialog-titlebar-buttonpane,
  .emulator-dialog .ui-dialog-titlebar-close,
  .mobile-player-hidden #id-emul { display: none !important; }

  .emulator-dialog .ui-dialog-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #edf4ff;
    padding: 0 12px;
  }
  .mobile-player-toggle { display: block; }
  .mobile-view-map, .mobile-player-toggle {
    min-height: 44px;
    background: transparent;
    border: 0;
    color: #0f59c1;
    font: inherit;
  }
  .emulator-dialog {
    position: fixed !important;
    box-sizing: border-box;
    top: auto !important;
    bottom: var(--webwigo-bottom-inset, 0px);
    left: 0 !important;
    width: 100% !important;
    max-width: none;
    border-radius: 16px 16px 0 0;
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    overflow: hidden;
    box-shadow: 0 -4px 18px #16324c26;
  }

  .emulator-dialog .ui-dialog-title { width: auto; font-weight: normal; }
  .mobile-player-toggle { white-space: nowrap; }
  .mobile-player-expanded #id-emul {
    height: var(--webwigo-panel-height) !important;
  }

  .emulator-dialog #id-emul {
    --webwigo-panel-height: min(58vh, calc(100vh - 136px));
    --webwigo-panel-height: min(45dvh, max(92px, calc(var(--webwigo-visible-height, 100dvh) - 107px)));
    max-height: var(--webwigo-panel-height) !important;
  }

  .mobile-player-expanded #id-emul {
    --webwigo-panel-height: min(69dvh, calc(var(--webwigo-visible-height, 100dvh) - 110px));
  }

  .emulator-dialog .wig-btn {
    min-height: 44px;
  }
}

.wig-input-actions .btn-success {
  background: #267142;
  border-color: #1e5d36;
}

.wig-input-actions .btn-success:hover, .wig-input-actions .btn-success:focus {
  background: #1e5d36;
}

.wig-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  padding: 8px;
  text-align: left;
  color: #fff;
  white-space: normal;
}

.wig-list-icon {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.wig-list-routing {
  flex: 0 0 54px;
  text-align: center;
}

.wig-list-routing p {
  margin: 0;
}

.wig-list-label {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.wig-list-name {
  display: block;
}

.wig-list-description {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.mobile-category-bar, .mobile-game-heading, .mobile-task-state, .mobile-row-icon.fa { display: none; }

@media (max-width: 700px), (max-height: 480px) and (pointer: coarse) {
  .emulator-dialog:has(#id-emul > :is(#id-mainscreen,#id-listscreen,#id-detailscreen):not([hidden])) .mobile-category-bar {
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    background: #1565d8;
  }
  .mobile-category-bar button {
    min-height: 58px;
    padding: 4px 0;
    background: transparent;
    color: #fff;
    border: 0;
    font: 16px/1.25 Arial,sans-serif;
  }
  .mobile-category-bar i { display: block; margin: 0 auto 3px; width: 44px; border-radius: 14px; font-size: 20px; line-height: 26px; }
  .emulator-dialog:has([data-category="1"]:is(#id-listscreen,#id-detailscreen):not([hidden])) button[data-category="1"] i,
  .emulator-dialog:has([data-category="2"]:is(#id-listscreen,#id-detailscreen):not([hidden])) button[data-category="2"] i,
  .emulator-dialog:has([data-category="3"]:is(#id-listscreen,#id-detailscreen):not([hidden])) button[data-category="3"] i,
  .emulator-dialog:has([data-category="4"]:is(#id-listscreen,#id-detailscreen):not([hidden])) button[data-category="4"] i { background: #ffc533; color: #0a2a5c; }
  .emulator-dialog:has(#id-mainscreen:not([hidden])) :is(#id-mainscreen,.ui-dialog-titlebar) { display: none; }
  .emulator-dialog:has(#id-mainscreen:not([hidden])) #id-emul {
    height: auto !important;
    padding: 0;
    min-height: 0 !important;
  }
  .emulator-dialog #id-emul > :is(#id-emul-status,#id-emul-completion):not([hidden]) { padding: 8px 12px; margin: 0; }
  .emulator-dialog.mobile-player-expanded:has(:is(#id-listscreen,#id-detailscreen):not([hidden])) #id-emul {
    --webwigo-panel-height: min(69dvh, calc(var(--webwigo-visible-height,100dvh) - 160px));
  }
  .mobile-game-heading, .mobile-task-state { display: block; margin: 0 0 8px; color: #0a2a5c; }
  .mobile-game-heading:empty { display: none; }
  .emulator-dialog #id-emul { background: white; color: #0a2a5c; text-align: left; font-family: Arial,sans-serif; }
  .emulator-dialog .wig-text { text-align: left; line-height: 1.5; }
  .emulator-dialog .wig-list-item { background: white; color: #0a2a5c; border: 0; border-bottom: 1px solid #dbe4ed; border-radius: 0; }
  .emulator-dialog .wig-list-item:hover, .emulator-dialog .wig-list-item:focus { background: #edf4ff; color: #0a2a5c; }
  .mobile-row-icon.fa { display: grid; place-items: center; width: 40px; height: 40px; flex: none; background: #edf4ff; color: #1565d8; border-radius: 10px; }
  .wig-list-routing { order: 2; }
  #id-listscreen[data-category="1"] :is(.wig-list-description, .wig-list-routing) { display: none; }
  #id-detailscreen { display: flex; flex-direction: column; }
  #id-detailscreen[hidden] { display: none; }
  #id-detailscreen-name { order: -1; margin: 0 0 8px; text-align: left; color: #0a2a5c; }
  .mobile-task-state { align-self: flex-start; padding: 4px 10px; background: #edf4ff; border-radius: 12px; }
  .emulator-dialog :is(#id-detailscreen-items,#id-getinput) .wig-btn,
  .emulator-dialog #id-messagebox button + button { background: #e7f0ff; border-color: #d8e6fa; color: #0b52b8; }
  .emulator-dialog #id-messagebox button:first-of-type { background: #1565d8; color: white; }
  .emulator-dialog :is(#id-messagebox,#id-getinput) .wig-btn { border-radius: 12px; white-space: normal; }

}

#id-emul:has(> #id-messagebox:not([hidden])) {
  display: flex;
  flex-direction: column;
}

#id-messagebox:not([hidden]) {
  display: flex;
  flex-direction: column;
  min-height: 3em;
}

.wig-message-body {
  min-height: 2em;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
  scrollbar-color: #708399 #eef2f6;
}

.wig-message-body .wig-image {
  max-height: none;
  height: auto;
}

.wig-message-actions {
  flex: none;
  padding-top: 8px;
}

.wig-message-more {
  flex: none;
  padding: 4px 0;
  border-top: 1px solid #ccd8e5;
  color: #27486e;
  font: 16px/20px Arial, sans-serif;
  text-align: center;
}

/* Cartridge popups fill the visible browser viewport at every screen size. */
.emulator-dialog:has(#id-emul > :is(#id-messagebox,#id-getinput,#id-detailscreen,.alert):not([hidden])) {
  & .ui-dialog-titlebar-buttonpane, & .ui-dialog-titlebar-close, & .ui-resizable-handle { display: none !important; }
  & .ui-dialog-titlebar { display: flex; align-items: center; justify-content: space-between; flex: none; }
  & .ui-dialog-title { width: auto; }
  & .mobile-view-map, & .mobile-player-toggle { min-height: 44px; padding: 0 12px; }

  &:not(.mobile-player-hidden) {
    position: fixed !important;
    top: auto !important;
    left: 0 !important;
    bottom: var(--webwigo-bottom-inset, 0px);
    margin: 0;
    z-index: 1100 !important;
    width: 100% !important;
    max-width: none;
    height: var(--webwigo-visible-height, 100dvh) !important;
    box-sizing: border-box;
    border: 0;
    border-radius: 0;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    & > #id-emul { flex: 1 1 0; min-height: 0 !important; max-height: none !important; height: auto !important; }
    & .mobile-player-toggle { display: none; }
    & .mobile-view-map { display: block; }
    & #id-messagebox:not([hidden]), & .wig-message-body { flex: 1; }
    & .wig-image { max-height: none; height: auto; }
    & .wig-text { text-align: left; }
  }
  &.mobile-player-hidden {
    position: fixed !important;
    left: auto !important;
    right: 0;
    top: auto !important;
    bottom: var(--webwigo-bottom-inset, 0px);
    width: min(400px, 100%) !important;
    height: auto !important;
    & > #id-emul { display: none !important; }
    & .mobile-player-toggle { display: block; }
  }
}

.emulator-dialog .wig-text { font-size: 18px; line-height: 1.5; }
