* {
  box-sizing: border-box;
  font-family: 'PRNumber3';
}

@font-face {
  font-family: 'PRNumber3';
  src: url('PRNumber3.ttf') format('truetype');
}

:root {
  --bg: #0d0f14;
  --panel: #121520;
  --accent: #4da3ff;
  --muted: #8aa0bf;
  --border: #1f2433;
  --grid: rgba(255, 255, 255, 0.12);
  --text: #e3e8f2;
  --danger: #e85b81;
  color: var(--text);
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 20%, #18203b, #0b0d12 45%),
    radial-gradient(circle at 80% 0%, #13243b, transparent 40%), var(--bg);
  height: 100%;
  overflow: hidden;
}

html {
  height: 100%;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(
    135deg,
    rgba(77, 163, 255, 0.16),
    rgba(77, 163, 255, 0)
  );
  backdrop-filter: blur(6px);
}

.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.03em;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

button {
  background: #1b2235;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.05s;
}

button:hover {
  background: #22304f;
  border-color: #2f3b5a;
}

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

.app-main {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.panel h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
}

.toolbox,
.palette {
  gap: 0.75rem;
  padding: 0.75rem;
}

.toolbox {
  grid-column: 1;
  grid-row: 1;
}

.drawing-area {
  grid-column: 2;
  grid-row: 1;
}

.palette {
  grid-column: 1 / -1;
  grid-row: 2;
}

.tool-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.tool-row label {
  color: var(--muted);
  font-size: 0.9rem;
}

.tool-row select {
  background: #0b0f18;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
}

.tool-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 36px;
  height: 36px;
}

.tool-row button svg {
  width: 18px;
  height: 18px;
}

.tools button.active {
  border-color: var(--accent);
  background: rgba(77, 163, 255, 0.16);
}

.swatch {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 2px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

.swatch .label {
  font-size: 0.7rem;
  color: #000;
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.6);
  padding: 0 0.3rem 0.25rem 0;
}

.caret-row {
  color: var(--muted);
  font-size: 0.95rem;
}

.drawing-area {
  min-height: 0;
  min-width: 0;
  flex: 1;
}

.drawing-area .status {
  display: flex;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.canvas-wrapper {
  flex: 1;
  overflow: auto;
  max-width: 100%;
  min-height: 0;
  height: 100%;
  background: #0b0f18;
  position: relative;
}

#drawingCanvas {
  display: block;
  background: #000;
  margin: 0 auto;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.3);
}

.app-footer .status {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.app-footer .status span + span::before {
  content: '·';
  margin: 0 0.5rem 0 0;
  color: var(--muted);
}

.swatch-grid {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
}

.swatch-button {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease,
    border-color 0.1s ease;
}

.swatch-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.swatch-button .label {
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 0.7rem;
  color: #000;
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.6);
}

.dialog-form {
  display: grid;
  gap: 0.75rem;
  min-width: 320px;
}

.dialog-form header {
  margin-bottom: 0.25rem;
}

.dialog-form h3 {
  margin: 0;
}

.dialog-form label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.dialog-form input,
.dialog-form select {
  background: #0b0f18;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dimensions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.palette-meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.dialog-links {
  display: flex;
  gap: 0.75rem;
}

.dialog-links a {
  color: var(--accent);
  text-decoration: none;
}

@media (max-width: 1024px) {
  .app-main {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .panel {
    min-height: 0;
  }

  .drawing-area {
    order: 1;
  }

  .toolbox {
    order: 2;
  }

  .palette {
    order: 3;
  }
}
