/* ==========================================================================
   1. Custom Properties
   ========================================================================== */

:root {
   --color-bg: #575655;
   --color-surface: #202020;
   --color-surface-dark: #333;
   --color-border: #969da8;
   --color-accent: #f9d339;
   --color-accent-dark: #f39646;
   --color-accent-hover: #fad644;
   --color-primary: #4e84fa;
   --color-primary-hover: #6092fd;
   --color-primary-dark: #3166c7;
   --color-danger: #d43c3c;
   --color-danger-hover: #d44a4a;
   --color-danger-dark: #b43434;
   --color-text-dark: #111;
   --color-text-light: #fff;
   --input-height: 35px;
}

/* ==========================================================================
   2. App Menu Bar
   ========================================================================== */

.app-menu-bar {
   display: flex;
   background-color: var(--color-surface);
   border-bottom: 1px solid var(--color-border);
   position: relative;
   z-index: 1000;
   user-select: none;
}

.menu-item {
   position: relative;
}

.menu-trigger {
   background: none;
   border: none;
   color: var(--color-text-light);
   padding: 6px 14px;
   font-size: 13px;
   cursor: pointer;
}

.menu-trigger:hover,
.menu-item.open .menu-trigger {
   background-color: var(--color-surface-dark);
}

.menu-dropdown {
   display: none;
   position: absolute;
   top: 100%;
   left: 0;
   background-color: var(--color-surface);
   border: 1px solid var(--color-border);
   list-style: none;
   margin: 0;
   padding: 4px 0;
   min-width: 160px;
   box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

.menu-item.open .menu-dropdown {
   display: block;
}

.menu-dropdown li a,
.menu-dropdown li button {
   display: block;
   width: 100%;
   padding: 7px 16px;
   background: none;
   border: none;
   color: var(--color-text-light);
   font-size: 13px;
   text-align: left;
   text-decoration: none;
   cursor: pointer;
   box-sizing: border-box;
}

.menu-dropdown li a:hover,
.menu-dropdown li button:hover {
   background-color: var(--color-surface-dark);
}

/* ==========================================================================
   3. Reset & Base
   ========================================================================== */

html {
   height: 100%;
   margin: 0;
   padding: 0;
}

body {
   font-family: 'Space Mono', monospace;
   background-color: var(--color-bg);
   margin: 0;
   padding: 0;
   color: var(--color-accent);
}

* {
   box-sizing: border-box;
}

button,
select,
input {
   font-family: inherit;
}

/* ==========================================================================
   3. Layout — Main Editor
   ========================================================================== */

#main-content {
   display: flex;
   flex-direction: column;
   height: 92vh;
   margin: 1vh 1vw;
}

.main-header {
   flex: none;
}

.main-header > img {
   margin-left: 8px;
}

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

.main-console {
   width: 100%;
   display: flex;
   height: 100%;
}

.tileset-aside {
   width: 20%;
   display: flex;
   flex-direction: column;
}

#tileset-header {
   flex: none;
   display: flex;
   border: 1px solid var(--color-border);
   margin-bottom: 0;
}

#tileset-container {
   flex: 6;
   overflow: auto;
   border-right: 1px solid var(--color-border);
   border-left: 1px solid var(--color-border);
   border-bottom: 1px solid var(--color-border);
}

#clipboard-header {
   flex: none;
   border-right: 1px solid var(--color-border);
   border-left: 1px solid var(--color-border);
   border-bottom: 1px solid var(--color-border);
}

#clipboard-container {
   flex: 3;
   display: flex;
   width: 100%;
   overflow: auto;
   border-right: 1px solid var(--color-border);
   border-left: 1px solid var(--color-border);
   border-bottom: 1px solid var(--color-border);
}

#clipboard-container > canvas {
   margin: auto;
}

.canvas-container {
   flex: 1;
   display: flex;
   flex-direction: column;
}

#map-header {
   flex: none;
   margin-bottom: 0;
   border-top: 1px solid var(--color-border);
   border-right: 1px solid var(--color-border);
   border-bottom: 1px solid var(--color-border);
}

#canvas-wrapper {
   flex: 1;
   min-height: 0;
   overflow: auto;
   border-right: 1px solid var(--color-border);
   border-bottom: 1px solid var(--color-border);
}

/* -- Tileset header layout ------------------------------------------------ */

.tile-header-title {
   text-align: center;
   width: 34%;
   font-size: 20px;
}

.tile-header-spacer {
   width: 33%;
}

.tile-tool-container {
   display: flex;
   justify-content: flex-end;
   width: 33%;
}

.tile-tool-container > button {
   margin-right: 8px;
}

/* -- Map header layout ---------------------------------------------------- */

.map-header-title {
   font-size: 20px;
   width: 34%;
   text-align: center;
}

.map-header-spacer {
   width: 33%;
}

.map-header-spacer > * {
   margin-left: 8px;
}

.map-tool-container {
   display: flex;
   width: 33%;
   justify-content: flex-end;
}

.map-tool-container > button {
   margin-left: 8px;
}

#btn-map-settings {
   margin-right: 8px;
}

/* -- Map canvas ----------------------------------------------------------- */

#map-canvas {
   cursor: none;
   display: block;
   margin: auto;
   background: #f4f8f9;
}

/* -- Tileset canvas ------------------------------------------------------- */

#tileset-selector-canvas {
   width: 100%;
   cursor: pointer;
}

.tile-canvas {
   border: 3px solid transparent;
}

.tile-canvas:hover {
   transform: scale(1.1);
}

.selected-tile {
   border: 3px solid var(--color-accent-hover);
}

/* ==========================================================================
   4. Components
   ========================================================================== */

/* -- Buttons -------------------------------------------------------------- */

.primary-button,
.secondary-button,
.exit-button {
   font-weight: bold;
   border: 0;
   border-top: 4px solid transparent;
   outline: 0;
   cursor: pointer;
}

.primary-button:hover,
.secondary-button:hover,
.exit-button:hover {
   transform: scale(1.05);
}

.primary-button {
   background: var(--color-primary);
   border-bottom: 4px solid var(--color-primary-dark);
   color: var(--color-text-light);
}

.primary-button:hover {
   background: var(--color-primary-hover);
}

.secondary-button {
   background: var(--color-accent);
   border-bottom: 4px solid var(--color-accent-dark);
   color: var(--color-text-dark);
}

.secondary-button:hover {
   background: var(--color-accent-hover);
}

#layers-btn:hover {
   cursor: default;
   transform: none;
}

.exit-button {
   background: var(--color-danger);
   border-bottom: 4px solid var(--color-danger-dark);
   color: var(--color-text-dark);
}

.exit-button:hover {
   background: var(--color-danger-hover);
}

/* -- Cards ---------------------------------------------------------------- */

.card {
   background: var(--color-surface);
   box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.5);
}

.card header {
   display: flex;
   justify-content: space-between;
   align-items: center;
}

.card-body {
   display: flex;
   width: 100%;
}

/* -- Modals --------------------------------------------------------------- */

.modal {
   display: none;
   position: fixed;
   z-index: 1;
   left: 0;
   top: 0;
   width: 100%;
   height: 100%;
   overflow: auto;
   background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
   position: relative;
   background-color: var(--color-surface-dark);
   margin: auto;
   border: 1px solid var(--color-border);
   padding: 16px;
}

.modal-header {
   border-bottom: 1px solid var(--color-border);
   text-align: center;
}

.modal-header > h2 {
   text-decoration: underline;
}

/* -- Forms ---------------------------------------------------------------- */

.form-input {
   border: 0;
   outline: 0;
   width: 100%;
   height: var(--input-height);
   border-bottom: 4px solid var(--color-border);
}

.form-select {
   font-weight: bold;
   border: 0;
   outline: 0;
   background: #94969c;
   width: 95%;
   height: 42px;
   color: var(--color-text-light);
   border-top: 4px solid transparent;
   border-bottom: 4px solid #696e77;
}

.form-select:hover {
   cursor: pointer;
}

.form-label {
   text-transform: uppercase;
   font-weight: bold;
   display: block;
}

.form-fieldset {
   margin-bottom: 10px;
   margin-top: 10px;
   padding: 30px;
}

.form-button {
   width: 100%;
   height: var(--input-height);
}

.half-width-input {
   width: calc(50% - 5px);
}

.radio-container {
   border: solid 1px;
   text-align: center;
}

.radio-input {
   width: auto;
   vertical-align: middle;
}

.radio-label {
   display: inline;
   vertical-align: middle;
}

/* -- Layer select --------------------------------------------------------- */

.layer-select {
   width: 128px;
   background-color: var(--color-accent);
   color: var(--color-text-dark);
   border-bottom: 4px solid var(--color-accent-dark);
}

/* -- Tool elements -------------------------------------------------------- */

.tool-element {
   height: 32px;
}

/* -- Alert ---------------------------------------------------------------- */

.alert {
   padding-left: 20px;
   background-color: #f44336;
   color: white;
   height: 75px;
   width: 90%;
   position: absolute;
   bottom: 10px;
}

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

.selection-context-menu-item {
   height: 25%;
   width: 100%;
   text-align: center;
   margin: auto;
}

.selection-context-menu-item:hover {
   background-color: var(--color-surface-dark);
}

.selection-context-menu-item:focus {
   background-color: var(--color-surface-dark);
   cursor: pointer;
}

.selection-context-menu-item-hover-hack {
   height: 25%;
   width: 100%;
   text-align: center;
   margin: auto;
   cursor: pointer;
   background-color: var(--color-surface-dark);
}

/* ==========================================================================
   5. Page-specific — Landing
   ========================================================================== */

.landing-page {
   display: flex;
   align-items: center;
   justify-content: center;
   min-height: 100vh;
}

.landing-menu-card {
   width: 92vw;
   max-width: 575px;
}

.landing-header {
   border-bottom: 1px solid var(--color-border);
   padding: 32px 24px;
   justify-content: center;
}

.landing-body {
   padding: 48px 0;
}

.landing-button {
   width: 100px;
   height: 100px;
   font-size: 52px;
}

.landing-menu {
   width: 80%;
   justify-content: space-between;
   margin: auto;
}

.landing-menu > div {
   padding: 10px;
}

.landing-button-container {
   display: flex;
   flex-direction: column;
   align-items: center;
   gap: 8px;
}

.button-label {
   font-size: 13px;
   font-weight: 600;
   text-align: center;
   padding: 4px 12px;
   border-radius: 4px;
   color: var(--color-text-light);
   cursor: pointer;
}

.primary-button + .button-label {
   background: #3d6ed4;
}

.secondary-button + .button-label {
   background: var(--color-accent);
   color: var(--color-text-dark);
}

.exit-button + .button-label {
   background: #b33232;
}

/* ==========================================================================
   6. Page-specific — New Project
   ========================================================================== */

.new-project-menu-card {
   display: none;
   height: 92vh;
   width: 92vw;
   margin: 4vh 4vw;
}

.new-project-menu-header {
   height: 12%;
   border-bottom: 1px solid var(--color-border);
}

.new-project-card-body {
   height: 88%;
   padding: 24px;
}

#new-project-menu {
   margin: auto;
   width: 100%;
}

.project-creation-panel {
   padding-bottom: 16px;
   width: 100%;
   margin: auto;
}

.project-creation-tile-fieldset {
   margin: auto;
}

/* ==========================================================================
   7. Page-specific — Export & Project Settings Modals
   ========================================================================== */

#export-modal-content {
   width: 640px;
   height: 268px;
   margin-top: 25vh;
}

.export-form-container {
   margin-top: 16px;
   line-height: var(--input-height);
   grid-template-columns: auto 1fr 1fr;
}

.export-form-container > div:nth-child(2) {
   grid-column: 2 / -1;
}

.export-form-container > div:nth-child(3) {
   grid-column: 3;
}

.export-form-label {
   float: right;
}


#export-button {
   height: var(--input-height);
   margin-top: 3px;
   float: right;
   width: 100%;
}

#project-settings-modal-content {
   width: 640px;
   height: 320px;
   margin-top: 25vh;
}

.project-settings-form-container {
   margin-top: 16px;
   line-height: var(--input-height);
   grid-template-columns: auto 1fr;
}

.project-settings-form-container > div:last-child {
   grid-column: 1 / -1;
}

.project-settings-label {
   float: right;
}

#project-settings-apply-button {
   float: right;
}

.settings-label-container {
   width: 25%;
   margin: auto;
}

.settings-form-input-container {
   width: 40%;
   margin: auto;
}

/* ==========================================================================
   8. Utilities
   ========================================================================== */

.flex-container {
   display: flex;
}

.grid-container {
   display: grid;
   width: 100%;
   gap: 16px;
}
