:root {
  color-scheme: light;
  --bg: #fdfcff;
  --surface: rgba(255, 255, 255, 0.45);
  --surface-strong: rgba(255, 255, 255, 0.65);
  --ink: #1e1e2f;
  --muted: #5e5e7f;
  --line: rgba(255, 255, 255, 0.8);
  --accent: #7879f1;
  --accent-dark: #4b4cac;
  --danger: #ff5e7e;
  --shadow: 0 16px 40px rgba(31, 38, 135, 0.12);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --glass-border: 1px solid rgba(255, 255, 255, 0.7);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden; /* Prevent scrolling on body */
  background: linear-gradient(135deg, #fbc2eb 0%, #a6c1ee 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Floating Layout Base */
.app-shell.floating-layout {
  position: relative;
  width: 100vw;
  height: 100vh;
}

/* Canvas Stage covers full viewport */
.board-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(30, 30, 47, 0.03) 1px, transparent 1px),
    linear-gradient(rgba(30, 30, 47, 0.03) 1px, transparent 1px),
    rgba(255, 255, 255, 0.3);
  background-size: 24px 24px;
  overscroll-behavior: contain;
}

#boardCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: default;
  touch-action: none;
  user-select: none;
}

#boardCanvas.has-image { cursor: pointer; }
#boardCanvas.is-moving { cursor: move; }
#boardCanvas.is-resizing { cursor: nwse-resize; }
#boardCanvas.is-panning { cursor: grabbing; }

/* Glass Panel Utilities */
.glass-panel {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: var(--glass-border);
  box-shadow: var(--shadow);
  z-index: 10;
}

/* Top Hero */
.hero {
  position: absolute;
  top: 24px;
  left: 24px;
  padding: 16px 24px;
  border-radius: var(--radius-lg);
  pointer-events: none; /* Let clicks pass through to canvas if needed, though background catches it */
}

.hero h1 {
  margin: 0 0 4px 0;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

/* Left Toolbar */
.left-toolbar {
  position: absolute;
  top: 120px;
  left: 24px;
  width: 76px;
  padding: 16px 8px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toolbar-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 4px 0;
}

.toolbar-spacer {
  flex-grow: 1;
}

.left-toolbar .button {
  width: 60px;
  height: 60px;
  padding: 0;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--ink);
  font-weight: 800;
  text-shadow: none;
  gap: 4px;
}

/* Right Properties */
.right-properties {
  position: absolute;
  top: 24px;
  right: 24px;
  bottom: 24px;
  width: 360px;
  padding: 24px;
  border-radius: var(--radius-lg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.right-properties::-webkit-scrollbar {
  width: 8px;
}
.right-properties::-webkit-scrollbar-track {
  background: transparent;
}
.right-properties::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}

/* Form Controls */
h2 {
  margin: 0 0 12px 0;
  font-size: 1.05rem;
}

.control-section {
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.4);
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.size-grid label {
  display: grid;
  gap: 6px;
}

.size-grid span,
.select-row > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.size-grid input,
.select-row select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 800;
  transition: all 0.2s ease;
}

.size-grid input:focus,
.select-row select:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(120, 121, 241, 0.3);
}

.size-grid input:disabled,
.select-row select:disabled {
  opacity: 0.56;
  cursor: not-allowed;
}

.file-picker {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 56px;
  margin-bottom: 12px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(120, 121, 241, 0.3);
}

.file-picker:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(120, 121, 241, 0.4);
  background: #898af5;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.option-stack {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.check-row,
.select-row {
  display: grid;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.select-row {
  grid-template-columns: 1fr;
}

.pixelize-summary {
  min-height: 3.8em;
  margin: 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: var(--glass-border);
  background: rgba(120, 121, 241, 0.15);
  color: var(--accent-dark);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.45;
}

/* Buttons */
.button {
  display: inline-grid;
  place-items: center;
  min-height: 44px;
  width: 100%;
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 10px;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(120, 121, 241, 0.3);
}

.button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(120, 121, 241, 0.4);
  background: #898af5;
}

.button.secondary {
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  box-shadow: 0 4px 15px rgba(31, 38, 135, 0.05);
}

.button.secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 20px rgba(31, 38, 135, 0.1);
}

.button.danger {
  background: var(--danger);
  box-shadow: 0 4px 15px rgba(255, 94, 126, 0.3);
  color: #fff;
}

.button.danger:hover:not(:disabled) {
  background: #ff7591;
  box-shadow: 0 6px 20px rgba(255, 94, 126, 0.4);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Meta List */
.meta-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0;
}

.meta-list div {
  min-height: 78px;
  padding: 12px;
  background: var(--surface-strong);
  border: var(--glass-border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.meta-list dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.meta-list dd {
  margin: 0;
  min-height: 1.35em;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#boardSizeText, #zoomText, #imagePositionText {
  font-variant-numeric: tabular-nums;
}

/* Notice */
.notice {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: var(--glass-border);
  background: rgba(120, 121, 241, 0.15);
  color: var(--accent-dark);
  line-height: 1.55;
  font-size: 0.85rem;
  font-weight: 650;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .right-properties {
    width: 300px;
  }
}
@media (max-width: 620px) {
  .hero { display: none; }
  .left-toolbar {
    top: auto;
    bottom: 24px;
    left: 24px;
    right: 24px;
    width: auto;
    flex-direction: row;
    height: 76px;
    padding: 8px 16px;
    overflow-x: auto;
  }
  .left-toolbar .button {
    width: auto;
    padding: 0 16px;
  }
  .toolbar-divider {
    width: 1px;
    height: 100%;
    margin: 0 4px;
  }
  .right-properties {
    top: 24px;
    left: 24px;
    right: 24px;
    bottom: 112px;
    width: auto;
  }
}
