/* The window: how its parts are laid out, and the top bar, the tool bar,
   the stage and the status bar. The side panel has panels.css. */

#app {
  display: grid;
  /* The side panel is as wide as its columns, see styles/panels.css. */
  grid-template-columns: var(--size-tool-bar) minmax(0, 1fr) auto;
  grid-template-rows: var(--size-top-bar) minmax(0, 1fr) var(--size-status-bar);
  grid-template-areas:
    "top top top"
    "tools stage side"
    "status status status";
  height: 100%;
}

/* Top bar */

#topBar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px 0 12px;
  background: var(--color-panel);
  border-bottom: 1px solid var(--color-border);
}

.appName {
  font-weight: 600;
  letter-spacing: 0.04em;
}

.menuButton {
  height: 24px;
  margin-left: 12px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
}

.menuButton:hover {
  background: var(--color-panel-raised);
}

/* The menus sit close together, like a menu bar. */
.menuButton + .menuButton {
  margin-left: 2px;
}

.fileName {
  margin-left: 8px;
  color: var(--color-text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}

/* The field the name turns into for renaming. */
#topBar .fileNameInput {
  flex: none;
  width: 180px;
  margin-left: 8px;
}

.editBar {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 12px;
  min-width: 0;
}

.editBar button {
  height: 22px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
}

.editBar button:hover:not(:disabled) {
  background: var(--color-panel-raised);
}

.editBar button:disabled {
  color: #ffffff;
  cursor: default;
}

.editBar .crumbSeparator {
  color: var(--color-text-dim);
}

#zoomSelect {
  width: 132px;
  height: 24px;
  margin-left: 8px;
  padding: 0 6px;
  background: var(--color-field);
  border: 1px solid var(--color-border);
  border-radius: 3px;
}

/* Tool bar */

#toolBar {
  grid-area: tools;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  /* The tool strip can get longer than the window is high. */
  overflow-y: auto;
  scrollbar-width: none;
  background: var(--color-panel);
  border-right: 1px solid var(--color-border);
}

.toolButton {
  width: 32px;
  height: 30px;
}

.toolSeparator {
  width: 24px;
  height: 1px;
  margin: 6px 0;
  background: var(--color-border);
}

/* Weighs the same as the hover of a tool button in base.css and has to
   come after it: the tool in use stays blue under the mouse. */
.toolButton.active {
  background: var(--color-accent);
  color: #ffffff;
}

/* The color wells at the bottom of the tool bar: fill in front, stroke
   behind it, swap at the top right, black and white at the bottom left. */

.colorWell {
  position: relative;
  flex: none;
  width: 38px;
  height: 38px;
  margin-top: 8px;
}

/* The modifiers of the tool in use, below the colors. The colors are put
   into the tool bar after them, so the order is set here. */
.toolModifiers {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  order: 1;
  margin-top: 10px;
}

.toolModifiers:empty {
  display: none;
}

.colorWellFill,
.colorWellStroke {
  position: absolute;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 0;
  cursor: pointer;
}

.colorWellFill {
  left: 0;
  top: 0;
  z-index: 1;
  border: 1px solid #ffffff;
  box-shadow: 0 0 0 1px var(--color-border);
}

/* The stroke shows as a frame: its color, or its gradient, around an
   empty middle. */
.colorWellStroke {
  --swatch-color: #000000;
  right: 0;
  bottom: 0;
  background: var(--swatch-image, linear-gradient(var(--swatch-color), var(--swatch-color)));
  border: 1px solid #ffffff;
}

.colorWellStroke::after {
  content: "";
  position: absolute;
  inset: 5px;
  background: var(--color-panel);
  border: 1px solid #ffffff;
}

.colorWellStroke.isNone {
  background: linear-gradient(to top right, #ffffff 46%, #e02020 46%, #e02020 54%, #ffffff 54%);
}

.colorWellStroke.isNone::after {
  display: none;
}

.colorWellSwap,
.colorWellDefault {
  position: absolute;
  width: 14px;
  height: 14px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--color-text);
  cursor: pointer;
}

.colorWellSwap {
  right: 0;
  top: 0;
}

.colorWellDefault {
  left: 0;
  bottom: 0;
}

.colorWellSwap svg,
.colorWellDefault svg {
  display: block;
  width: 14px;
  height: 14px;
}

/* Stage */

#stageArea {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  background: #3c3c3c;
}

#stageArea canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#stageCanvas {
  pointer-events: none;
}

/* The field one types text into, lying over the text on the stage. It is
   placed, scaled and turned by a transform, see source/ui/textEditor.js. */

.textEditor {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.textEditorField {
  display: block;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  outline: 1px solid #4f9fff;
  overflow: hidden;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

/* The handle at the top right corner: round while the field grows with its
   text, square once it has a fixed width. */
.textEditorHandle {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1px solid #111111;
  border-radius: 50%;
  cursor: ew-resize;
}

.textEditorHandle.isFixed {
  border-radius: 0;
}

/* Status bar */

#statusBar {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--color-panel);
  border-top: 1px solid var(--color-border);
  color: var(--color-text-dim);
  font-variant-numeric: tabular-nums;
  white-space: pre;
}
