:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --ink: #1b2a25;
  --muted: #52635c;
  --accent: #156f5a;
  --accent-strong: #0f5f4c;
  --shadow: 0 14px 40px rgba(21, 37, 31, 0.12);
  --radius: 14px;
  --app-vh: 1vh;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: calc(var(--app-vh) * 100);
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 10% 10%, #d9efe7 0%, transparent 34%),
    radial-gradient(circle at 92% 86%, #e8f0d8 0%, transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.wrapper {
  display: grid;
  height: calc(var(--app-vh) * 100);
  width: 100%;
  gap: 12px;
  padding: 12px;
  grid-template-columns: 66px 260px minmax(420px, 1fr);
  grid-template-rows: minmax(68px, auto) minmax(320px, 1fr) 108px;
  grid-template-areas:
    "header header header"
    "sidebar content content"
    "colourP colourP options";
}

.box,
#content {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 0;
}

.header {
  grid-area: header;
  display: grid;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  grid-template-columns: minmax(200px, 1.2fr) minmax(300px, 1fr);
  grid-template-rows: auto;
  grid-template-areas:
    "brand actions";
}

.brandBlock {
  grid-area: brand;
  height: 100%;
  display: flex;
  align-items: center;
}

.appBrandRow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 100%;
}

#appHeaderIcon {
  height: 90%;
  width: auto;
  aspect-ratio: 1 / 1;
  min-height: 28px;
  max-height: 52px;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(16, 45, 37, 0.18);
}

.appTitle {
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  font-weight: 700;
}

.actionsRow {
  grid-area: actions;
  justify-self: end;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 100%;
}

.statusRow {
  display: none;
}

#statusText {
  color: var(--accent-strong);
  font-weight: 600;
}

button,
.dropbtn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.94rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

button,
.dropbtn,
.sideBarItem,
.colourSwatches,
.shortcutsPanel summary,
input,
select,
textarea {
  touch-action: manipulation;
}

.actionsRow button,
.actionsRow .dropbtn {
  padding: 7px 11px;
  font-size: 0.82rem;
}

button:hover,
.dropbtn:hover,
.dropbtn:focus {
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #5f7f75;
}

button:active,
.dropbtn:active {
  transform: translateY(1px);
}

.sidebarWrap {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
}

#sidebar {
  width: 100%;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}

.sideBarItem {
  width: 42px;
  height: 42px;
  border: 2px solid transparent;
  padding: 4px;
  margin: 3px auto;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.sideBarItem:hover {
  background: #e8f2ee;
}

.sideBarItem img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sideBarItem.toolSelected {
  background: #f2faf6;
  border-color: #1b76e8;
  box-shadow: 0 2px 8px rgba(21, 37, 31, 0.12);
}

.toolbarScrollButton {
  width: 36px;
  height: 26px;
  padding: 0;
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1;
}

#content {
  grid-area: content;
  overflow: hidden;
  position: relative;
  min-height: 0;
  overscroll-behavior: contain;
}

canvas {
  touch-action: none;
  display: block;
}

.colourPalette {
  grid-area: colourP;
  display: flex;
  flex-flow: wrap;
  align-content: flex-start;
  gap: 2px;
  padding: 8px 10px 8px 10px;
  overflow: auto;
}

.colourSwatches {
  box-sizing: border-box;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  margin: 2px;
}

.options {
  grid-area: options;
  padding: 8px 12px;
  overflow-y: auto;
  font-size: 0.9rem;
}

#optionName {
  margin-right: 8px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 1rem;
  font-weight: 600;
}

#scissorsButton {
  margin-top: 10px;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #f8fbfa;
  min-width: 280px;
  border-radius: 10px;
  border: 1px solid #dce8e3;
  box-shadow: 0 10px 24px rgba(10, 30, 22, 0.12);
  z-index: 5;
}

.dropdown-content div {
  color: #10251f;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.layerMenuRow {
  position: relative;
  padding-right: 128px !important;
  cursor: pointer;
}

.dropdown-content div:hover {
  background-color: #e8f2ee;
}

.show {
  display: block;
}

.selected {
  background-color: #dcefe8;
}

.deleteLayerButton {
  background-color: #6d7a75;
  color: white;
  margin-top: -8px;
  margin-left: 4px;
  padding: 5px 7px;
  border-radius: 8px;
  font-size: 0.72rem;
}

.renameLayerButton {
  background-color: #607d73;
  color: white;
  margin-top: -8px;
  margin-left: 6px;
  padding: 5px 7px;
  border-radius: 8px;
  font-size: 0.72rem;
}

.option-hidden {
  display: none;
}

input[type="range"],
input[type="text"],
select {
  margin-top: 5px;
  height: 28px;
  width: min(220px, 100%);
  border-radius: 8px;
  border: 1px solid #b8cbc3;
  box-sizing: border-box;
}

input[type="text"],
select {
  padding-left: 8px;
  background: #fff;
}

input[type="range"] {
  accent-color: #2f9a7e;
  height: 20px;
}

.canvasTextEditor {
  position: absolute;
  min-width: 220px;
  max-width: min(360px, 80%);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #bfd1c8;
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(10, 30, 22, 0.16);
  z-index: 30;
  transform: translate(0, 0);
}

.canvasTextEditorBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid #dfebe5;
  cursor: move;
  user-select: none;
}

.canvasTextEditorTitle {
  font-size: 0.74rem;
  font-weight: 700;
  color: #2a4039;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.canvasTextEditorActions {
  display: flex;
  gap: 6px;
}

.canvasTextEditorActions button {
  padding: 4px 8px;
  font-size: 0.72rem;
  border-radius: 7px;
}

.canvasTextInput {
  width: calc(100% - 16px);
  min-height: 72px;
  margin: 8px;
  resize: vertical;
  border: 1px solid #c8d9d1;
  border-radius: 8px;
  padding: 8px;
  box-sizing: border-box;
  background: #fff;
  color: #1f332d;
  line-height: 1.25;
}

.canvasTextInput:focus {
  outline: 2px solid rgba(47, 154, 126, 0.35);
  border-color: #2f9a7e;
}

.shortcutsPanel {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 20;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #d8e5de;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(13, 39, 30, 0.12);
  max-width: 580px;
  color: #243a33;
}

.shortcutsPanel summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

.shortcutsPanel summary::-webkit-details-marker {
  display: none;
}

.shortcutsContent {
  padding: 0 12px 10px 12px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: #52635c;
}

#statusToast {
  position: fixed;
  left: 14px;
  bottom: 14px;
  max-width: min(420px, calc(100% - 28px));
  background: rgba(27, 42, 37, 0.92);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.25;
  box-shadow: 0 8px 22px rgba(15, 28, 24, 0.24);
  z-index: 24;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

#statusToast.show {
  opacity: 1;
}

@media (max-width: 1000px) {
  .wrapper {
    grid-template-columns: 64px minmax(0, 1fr);
    grid-template-rows: auto minmax(280px, 1fr) 94px 110px;
    grid-template-areas:
      "header header"
      "sidebar content"
      "colourP colourP"
      "options options";
  }

  .header {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "actions";
  }

  .actionsRow {
    justify-self: start;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    padding-bottom: 2px;
  }

  #appHeaderIcon {
    min-height: 24px;
    max-height: 42px;
  }

  .colourPalette {
    padding-left: 8px;
    min-height: 0;
  }

  .shortcutsPanel {
    left: 8px;
    right: 8px;
    max-width: none;
  }
}

@media (max-width: 820px) {
  .wrapper {
    gap: 8px;
    padding: 8px;
    grid-template-columns: 56px minmax(0, 1fr);
    grid-template-rows: auto minmax(220px, 1fr) 88px 128px;
    grid-template-areas:
      "header header"
      "sidebar content"
      "colourP colourP"
      "options options";
  }

  .header {
    padding: 8px 10px;
    gap: 6px;
  }

  .appTitle {
    font-size: 1rem;
  }

  .actionsRow {
    gap: 6px;
  }

  .actionsRow button,
  .actionsRow .dropbtn {
    height: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 6px 8px;
    font-size: 0.76rem;
    border-radius: 8px;
  }

  .sidebarWrap {
    gap: 4px;
    padding: 4px 3px;
  }

  .toolbarScrollButton {
    width: 30px;
    height: 22px;
    font-size: 0.78rem;
  }

  .sideBarItem {
    width: 36px;
    height: 36px;
    padding: 2px;
    margin: 2px auto;
  }

  .sideBarItem img {
    width: 100%;
    height: 100%;
  }

  .colourPalette {
    min-height: 80px;
    padding: 6px 8px;
  }

  .colourSwatches {
    width: 22px;
    height: 22px;
  }

  .options {
    min-height: 120px;
    padding: 8px 10px;
    font-size: 0.86rem;
    -webkit-overflow-scrolling: touch;
  }

  input[type="range"],
  input[type="text"],
  select {
    width: 100%;
    max-width: 100%;
  }

  .canvasTextEditor {
    min-width: 180px;
    max-width: min(300px, 85%);
  }

  .shortcutsPanel summary {
    font-size: 0.76rem;
    padding: 7px 10px;
  }

  .shortcutsContent {
    font-size: 0.72rem;
    padding: 0 10px 8px 10px;
  }

  .shortcutsPanel {
    display: none;
  }

  #statusToast {
    display: none !important;
  }

  #statusToast.show {
    display: none !important;
  }
}

@media (max-width: 560px) {
  .wrapper {
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-rows: auto minmax(180px, 1fr) 84px 120px;
  }

  .header {
    padding: 6px 8px;
  }

  .appBrandRow {
    gap: 7px;
  }

  #appHeaderIcon {
    min-height: 22px;
    max-height: 34px;
  }

  .appTitle {
    font-size: 0.95rem;
  }

  .actionsRow {
    gap: 5px;
  }

  .actionsRow button,
  .actionsRow .dropbtn {
    height: 32px;
    min-height: 32px;
    padding: 6px 7px;
    font-size: 0.72rem;
  }

  .sideBarItem {
    width: 32px;
    height: 32px;
  }

  .sideBarItem img {
    width: 100%;
    height: 100%;
  }

  .toolbarScrollButton {
    width: 26px;
    height: 20px;
    font-size: 0.72rem;
  }
}

@media (max-height: 760px) and (max-width: 1100px) {
  .wrapper {
    gap: 8px;
    padding: 8px;
    grid-template-rows: auto minmax(170px, 1fr) 76px 92px;
  }

  .header {
    padding: 6px 8px;
  }

  #appHeaderIcon {
    max-height: 36px;
  }

  .actionsRow button,
  .actionsRow .dropbtn {
    padding: 6px 8px;
    font-size: 0.74rem;
  }

  .colourPalette {
    padding: 6px;
  }

  .colourSwatches {
    width: 20px;
    height: 20px;
    border-radius: 5px;
  }

  .options {
    font-size: 0.82rem;
    padding: 6px 8px;
  }

  .shortcutsPanel {
    bottom: 8px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .wrapper {
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-rows: auto minmax(120px, 1fr) 72px 84px;
  }

  .actionsRow {
    max-width: calc(100vw - 24px);
  }

  .sideBarItem {
    width: 30px;
    height: 30px;
  }

  .sideBarItem img {
    width: 100%;
    height: 100%;
  }
}
