/* rimu98 — late-90s application controls.
   Bevels follow the classic 4-tone recipe: highlight, light, shadow, dark. */
:root {
  --face: #c0c0c0;
  --light: #dfdfdf;
  --hilite: #ffffff;
  --shadow: #808080;
  --dark: #0a0a0a;
  --desktop: #008080;
  --title-a: #000080;
  --title-b: #1084d0;
  --title-off-a: #808080;
  --title-off-b: #b5b5b5;
  --select: #000080;
  --ui-font: Tahoma, 'MS Sans Serif', 'Microsoft Sans Serif', 'Segoe UI', Arial, sans-serif;

  --raised: inset -1px -1px var(--dark), inset 1px 1px var(--hilite), inset -2px -2px var(--shadow), inset 2px 2px var(--light);
  --pressed: inset -1px -1px var(--hilite), inset 1px 1px var(--dark), inset -2px -2px var(--light), inset 2px 2px var(--shadow);
  --sunken: inset -1px -1px var(--hilite), inset 1px 1px var(--shadow), inset -2px -2px var(--light), inset 2px 2px var(--dark);
  --thin-up: inset -1px -1px var(--shadow), inset 1px 1px var(--hilite);
  --thin-down: inset -1px -1px var(--hilite), inset 1px 1px var(--shadow);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--desktop);
  color: #000;
  font: 11px/1.3 var(--ui-font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: none;
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: default; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: -100px; top: 0; }
svg { flex-shrink: 0; }

/* ---------- Generic window pieces ---------- */
.window {
  background: var(--face);
  box-shadow: var(--raised);
  padding: 3px;
}
.titlebar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 2px 0 3px;
  background: linear-gradient(90deg, var(--title-a), var(--title-b));
  color: #fff;
  font-weight: bold;
  user-select: none;
  flex-shrink: 0;
}
.titlebar.inactive { background: linear-gradient(90deg, var(--title-off-a), var(--title-off-b)); color: var(--light); }
.title-icon { display: inline-flex; }
.title-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-buttons { display: flex; gap: 2px; }
.tb-btn {
  width: 16px; height: 14px; padding: 0;
  background: var(--face); border: 0; box-shadow: var(--raised);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: bold; color: #000; line-height: 1;
}
.tb-btn:active { box-shadow: var(--pressed); }
.title-buttons .tb-btn:last-child { margin-left: 2px; }

.btn {
  min-width: 75px; height: 23px; padding: 0 10px;
  background: var(--face); border: 0; box-shadow: var(--raised);
}
.btn:active { box-shadow: var(--pressed); padding-top: 1px; padding-left: 11px; }
.btn:focus-visible { outline: 1px dotted #000; outline-offset: -5px; }
.btn.default { box-shadow: inset 0 0 0 1px var(--dark), inset -2px -2px var(--dark), inset 1px 1px var(--hilite), inset -3px -3px var(--shadow), inset 2px 2px var(--light); }
.btn.small { min-width: 0; height: 21px; padding: 0 6px; }
.btn[disabled] { color: var(--shadow); text-shadow: 1px 1px var(--hilite); }

.field {
  height: 21px;
  background: #fff;
  border: 0;
  box-shadow: var(--sunken);
  padding: 2px 4px;
  border-radius: 0;
  outline: none;
}
select.field { padding: 1px 2px; }
textarea.field { height: auto; resize: vertical; padding: 4px; }
input[type="number"].field { width: 64px; }
input[type="range"] { accent-color: var(--select); }
input[type="checkbox"] { accent-color: var(--select); margin: 0 4px 0 0; vertical-align: -2px; }
.sunken { box-shadow: var(--sunken); background: #fff; }

fieldset {
  border: 0;
  box-shadow: inset -1px -1px var(--hilite), inset 1px 1px var(--shadow), -1px -1px var(--shadow) inset, 1px 1px var(--hilite);
  border: 1px solid var(--shadow);
  border-right-color: var(--hilite);
  border-bottom-color: var(--hilite);
  outline: 1px solid var(--hilite);
  outline-offset: -2px;
  margin: 8px 0 4px;
  padding: 8px 8px 8px;
}
legend { padding: 0 3px; }

/* ---------- App window ---------- */
.app-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Menu bar */
.menubar { display: flex; padding: 1px 0; flex-shrink: 0; user-select: none; }
.menu-title {
  background: none; border: 0; padding: 2px 7px;
}
.menu-title:hover { box-shadow: var(--thin-up); }
.menu-title.open { box-shadow: var(--thin-down); }

/* Toolbars */
.toolbar-row {
  display: flex;
  flex-shrink: 0;
  border-top: 1px solid var(--shadow);
  box-shadow: inset 0 1px var(--hilite);
  padding: 2px 0 1px;
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar-row::-webkit-scrollbar { display: none; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 1px 4px 1px 2px;
  white-space: nowrap;
}
.grip { width: 3px; height: 20px; box-shadow: var(--thin-up); margin-right: 4px; flex-shrink: 0; }
.sep { width: 2px; height: 20px; margin: 0 4px; box-shadow: inset 1px 0 var(--shadow), inset -1px 0 var(--hilite); flex-shrink: 0; }
.tool {
  min-width: 23px; height: 22px; padding: 0 3px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; position: relative; flex-shrink: 0;
}
.tool:hover { box-shadow: var(--thin-up); }
.tool:active, .tool.on { box-shadow: var(--thin-down); }
.tool.on { background: repeating-conic-gradient(var(--hilite) 0 25%, var(--face) 0 50%) 0 0 / 2px 2px; }
.tool.txt { font-size: 13px; width: 23px; font-family: 'Times New Roman', serif; }
.tool[disabled] { opacity: .45; }
.tool.drop { min-width: 11px; width: 11px; padding: 0; font-size: 8px; }
.color-tool { display: inline-flex; }
.color-tool .tool:first-child { flex-direction: column; gap: 0; padding-top: 1px; }
.swatch-bar { display: block; width: 16px; height: 4px; margin-top: -2px; background: #f00; }
.font-select { width: 150px; }
.size-select { width: 50px; margin-left: 3px; }
.zoom-select { width: 92px; margin: 0 3px 0 6px; }

/* ---------- Main area ---------- */
.main {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
  gap: 3px;
  padding-top: 3px;
  border-top: 1px solid var(--shadow);
  box-shadow: inset 0 1px var(--hilite);
}
.panel {
  width: 248px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--face);
  box-shadow: var(--raised);
  padding: 3px;
}
.panel.collapsed { display: none; }
.panel-title {
  height: 18px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2px 0 4px;
  background: linear-gradient(90deg, var(--title-a), var(--title-b));
  color: #fff; font-weight: bold; flex-shrink: 0; user-select: none;
}
.panel-close {
  width: 14px; height: 12px; padding: 0; font-size: 8px; line-height: 1;
  background: var(--face); color: #000; border: 0; box-shadow: var(--raised);
}
.panel-hint { padding: 4px 2px 0; color: #404040; flex-shrink: 0; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; padding: 6px 2px 0; position: relative; z-index: 1; flex-shrink: 0; }
.tab {
  background: var(--face); border: 0; padding: 2px 6px 3px;
  box-shadow: inset 1px 1px var(--hilite), inset -1px 0 var(--dark), inset -2px 0 var(--shadow);
  border-radius: 3px 3px 0 0;
  margin-bottom: -1px;
  margin-top: 2px;
}
.tab.active { margin-top: 0; padding-bottom: 5px; position: relative; z-index: 2; margin-left: -2px; margin-right: -2px; padding-left: 8px; padding-right: 8px; }
.tab:focus-visible { outline: 1px dotted #000; outline-offset: -4px; }
.tab-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px;
  min-height: 0;
  background: var(--face);
  box-shadow: inset 1px 1px var(--hilite), inset -1px -1px var(--dark), inset -2px -2px var(--shadow);
}
.tab-body h4 { margin: 8px 0 4px; font-size: 11px; }
.tab-body h4:first-child { margin-top: 0; }

/* Toolbox tiles */
.tile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tile-grid.two { grid-template-columns: repeat(2, 1fr); }
.tile-grid.four { grid-template-columns: repeat(4, 1fr); }
.tile {
  background: #fff;
  border: 0;
  box-shadow: var(--sunken);
  padding: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px;
  cursor: grab;
  user-select: none;
  overflow: hidden;
}
.tile:hover { outline: 1px dotted #000; outline-offset: -4px; }
.tile.active { background: #ffffcc; outline: 2px solid var(--select); outline-offset: -4px; }
.tile svg { width: 100%; height: 40px; display: block; }
.tile .tile-label { font-size: 10px; color: #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tile.wa svg { height: 34px; }
.tile.swatch { min-height: 40px; padding: 0; cursor: pointer; }
.tile.swatch .sw { width: 100%; height: 34px; }
.tile.border-tile { min-height: 50px; cursor: pointer; }
.tile.border-tile .bp { width: 46px; height: 34px; background: #fff; }
.tile.template { min-height: 0; flex-direction: row; justify-content: flex-start; text-align: left; gap: 8px; padding: 6px; cursor: pointer; }
.tile.template .tpl-thumb { width: 54px; height: 70px; flex-shrink: 0; overflow: hidden; position: relative; box-shadow: 1px 1px 0 #000; background: #fff; }
.tile.template .tpl-thumb .page { transform-origin: 0 0; position: absolute; left: 0; top: 0; pointer-events: none; }
.tile.template b { display: block; margin-bottom: 2px; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row label { min-width: 52px; }
.cat-select { width: 100%; margin-bottom: 6px; }
.big-btn { width: 100%; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; justify-content: flex-start; }

/* ---------- Document area ---------- */
.docarea {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 20px 1fr;
  grid-template-rows: 20px 1fr;
  box-shadow: var(--sunken);
  padding: 2px;
}
.ruler { background: var(--face); overflow: hidden; position: relative; }
.ruler svg { position: absolute; left: 0; top: 0; }
.hruler { border-bottom: 1px solid var(--shadow); }
.vruler { border-right: 1px solid var(--shadow); }
.ruler-corner { background: var(--face); border-right: 1px solid var(--shadow); border-bottom: 1px solid var(--shadow); }
.workspace {
  overflow: auto;
  background: var(--shadow);
  position: relative;
  outline: none;
  padding: 28px;
}
.page-holder { position: relative; margin: 0 auto; }
.page-scaler { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#page { box-shadow: 5px 5px 0 #000; }
#page .el { cursor: move; touch-action: none; }
#page .el.editing { cursor: text; }
#page .el.editing .el-text { cursor: text; user-select: text; -webkit-user-select: text; }
#page .el-text { user-select: none; -webkit-user-select: none; }
#page img { -webkit-user-drag: none; }
.workspace.drop-target #page { outline: 3px dashed #ff00ff; outline-offset: 4px; }

/* Selection overlay */
.overlay { position: absolute; left: 0; top: 0; pointer-events: none; --inv: 1; }
.overlay .grid-lines {
  position: absolute; inset: 0;
  background:
    linear-gradient(90deg, rgba(0,0,128,.16) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(rgba(0,0,128,.16) 1px, transparent 1px) 0 0 / 24px 24px;
}
.sel-box {
  position: absolute;
  outline: calc(1px * var(--inv)) dashed var(--select);
}
.sel-box.multi { outline-style: dotted; outline-color: #ff00ff; }
.sel-box.editing {
  outline: none;
}
.sel-box.editing::before {
  content: '';
  position: absolute;
  inset: calc(-6px * var(--inv));
  border: calc(5px * var(--inv)) solid transparent;
  border-image: repeating-linear-gradient(45deg, #000 0 1.5px, transparent 1.5px 4px) 5;
}
.handle {
  position: absolute;
  width: calc(9px * var(--inv)); height: calc(9px * var(--inv));
  margin: calc(-4.5px * var(--inv)) 0 0 calc(-4.5px * var(--inv));
  background: #fff;
  border: calc(1px * var(--inv)) solid #000;
  pointer-events: auto;
  touch-action: none;
}
.handle[data-h="nw"], .handle[data-h="se"] { cursor: nwse-resize; }
.handle[data-h="ne"], .handle[data-h="sw"] { cursor: nesw-resize; }
.handle[data-h="n"], .handle[data-h="s"] { cursor: ns-resize; }
.handle[data-h="e"], .handle[data-h="w"] { cursor: ew-resize; }
.handle.rot {
  background: #00ff00; border-radius: 50%; cursor: grab;
  width: calc(11px * var(--inv)); height: calc(11px * var(--inv));
  margin: calc(-5.5px * var(--inv)) 0 0 calc(-5.5px * var(--inv));
}
.rot-stem { position: absolute; left: 50%; width: 0; border-left: calc(1px * var(--inv)) solid #000; }
.marquee { position: absolute; border: calc(1px * var(--inv)) dotted #000; background: rgba(0,0,128,.08); }
.guide { position: absolute; background: #ff00ff; }
.guide.v { width: calc(1px * var(--inv)); top: 0; bottom: 0; }
.guide.h { height: calc(1px * var(--inv)); left: 0; right: 0; }

/* ---------- Format panel ---------- */
.props-body { flex: 1; overflow-y: auto; padding: 4px 6px 8px; min-height: 0; }
.props-body .empty { color: #404040; padding: 12px 4px; text-align: center; }
.props-body .empty svg { width: 64px; height: 64px; display: block; margin: 8px auto; }
.prop-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 4px 6px; align-items: center; }
.prop-grid input[type="number"].field { width: 100%; }
.prop-row { display: flex; align-items: center; gap: 6px; margin: 5px 0; flex-wrap: wrap; }
.prop-row > label:first-child { width: 58px; flex-shrink: 0; }
.prop-row .field { flex: 1; min-width: 0; }
.color-btn {
  height: 21px; min-width: 70px; padding: 0 4px 0 3px; border: 0;
  background: var(--face); box-shadow: var(--raised);
  display: inline-flex; align-items: center; gap: 4px;
}
.color-btn:active { box-shadow: var(--pressed); }
.color-btn .chip { width: 22px; height: 13px; border: 1px solid #000; }
.color-btn .chip.none { background: repeating-linear-gradient(135deg, #fff 0 3px, #f00 3px 4px, #fff 4px 7px) !important; }
.mini-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.mini-grid.six { grid-template-columns: repeat(4, 1fr); }
.mini-grid .tile { min-height: 34px; padding: 2px; cursor: pointer; }
.mini-grid .tile svg { height: 26px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 3px; }
.btn-row .btn { min-width: 0; flex: 1; padding: 0 4px; }
textarea.wa-text { width: 100%; min-height: 54px; font-size: 13px; }

/* ---------- Menus ---------- */
.menu {
  position: fixed;
  z-index: 1000;
  background: var(--face);
  box-shadow: var(--raised);
  padding: 3px;
  min-width: 180px;
  user-select: none;
}
.menu-item {
  display: flex; align-items: center; width: 100%;
  background: none; border: 0; text-align: left;
  padding: 3px 18px 3px 4px; gap: 4px; white-space: nowrap;
}
.menu-item .mi-icon { width: 18px; display: inline-flex; justify-content: center; }
.menu-item .mi-label { flex: 1; }
.menu-item .mi-key { margin-left: 24px; }
.menu-item:hover:not([disabled]), .menu-item:focus-visible { background: var(--select); color: #fff; outline: none; }
.menu-item[disabled] { color: var(--shadow); text-shadow: 1px 1px var(--hilite); }
.menu-sep { height: 2px; margin: 3px 1px; box-shadow: inset 0 1px var(--shadow), inset 0 -1px var(--hilite); }
/* Palette popup */
.palette {
  position: fixed; z-index: 1001; background: var(--face); box-shadow: var(--raised); padding: 6px; width: 172px;
}
.palette .pal-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; margin: 4px 0; }
.palette .pal-sw { width: 16px; height: 16px; border: 0; padding: 0; box-shadow: var(--thin-down), inset 0 0 0 2px var(--face); outline: 1px solid var(--shadow); outline-offset: -1px; }
.palette .pal-sw:hover { outline: 2px solid #000; }
.palette .btn { width: 100%; min-width: 0; height: 22px; }

/* ---------- Dialogs ---------- */
#dialogLayer:empty { display: none; }
#dialogLayer { position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { width: 420px; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.dialog .titlebar .tb-btn { font-size: 9px; }
.dialog-body { padding: 10px 8px 8px; overflow: auto; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 6px; padding: 4px 8px 8px; }
.dialog.wide { width: 560px; }
.dialog p { margin: 0 0 8px; }
.wa-gallery { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 4px; }
.wa-gallery .tile { min-height: 58px; }
.wa-gallery .tile svg { height: 44px; }
.tip-body { display: flex; gap: 12px; background: #fff; box-shadow: var(--sunken); padding: 14px; min-height: 140px; }
.tip-body .tip-icon svg { width: 48px; height: 48px; }
.tip-body h3 { margin: 0 0 8px; font-family: 'Times New Roman', serif; font-size: 20px; }
.tip-body p { font-size: 12px; }
.kbd-table { width: 100%; border-collapse: collapse; background: #fff; box-shadow: var(--sunken); }
.kbd-table td { padding: 3px 8px; border-bottom: 1px solid #eee; }
.kbd-table td:first-child { font-weight: bold; white-space: nowrap; }
.msg-row { display: flex; gap: 12px; align-items: flex-start; }
.msg-icon { width: 32px; height: 32px; flex-shrink: 0; }
.about-logo { font-family: 'Times New Roman', serif; font-size: 34px; font-weight: bold; font-style: italic; color: #000080; text-shadow: 2px 2px 0 #c0c0c0; margin: 0 0 6px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%);
  background: #ffffe1; border: 1px solid #000; padding: 6px 10px; z-index: 1100;
  box-shadow: 2px 2px 0 rgba(0,0,0,.4); max-width: calc(100vw - 32px);
}

/* ---------- Print ---------- */
#printArea { display: none; }
@media print {
  body { display: block; overflow: visible; background: #fff; height: auto; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block; }
  #printArea .page { box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printArea * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Narrow screens ---------- */
@media (max-width: 1100px) {
  .panel { position: absolute; top: 3px; bottom: 0; z-index: 50; box-shadow: var(--raised), 4px 4px 0 rgba(0,0,0,.35); }
  .toolbox { left: 0; }
  .props { right: 0; }
}
@media (max-width: 640px) {
  .panel { width: min(280px, calc(100vw - 32px)); }
  .docarea { grid-template-columns: 0 1fr; grid-template-rows: 0 1fr; }
  .workspace { padding: 16px; }
}
