:root {
  --panel-bg: #f7f7f4;
  --panel-line: #d8d6cf;
  --ink: #202124;
  --muted: #62666d;
  --accent: #f45757;
  --blue: #276ef1;
  --surface: #ffffff;
  --preview-bg: #eef1f4;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--preview-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="color"],
input[type="number"],
input[type="file"] {
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

button {
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9ea3aa;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
}

input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 3px;
}

input[type="file"] {
  width: 100%;
  min-height: 36px;
  padding: 7px;
  background: #fff;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr) minmax(280px, 1fr);
  height: 100vh;
  min-width: 900px;
}

.control-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-line);
}

.control-panel h1 {
  margin: 0 0 20px;
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

.panel-section {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.action-grid button {
  font-weight: 700;
}

.piece-tray {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.piece-token {
  display: grid;
  grid-template-rows: 70px auto;
  place-items: center;
  width: 100%;
  min-height: 100px;
  padding: 8px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: #fff;
  user-select: none;
  touch-action: none;
}

.piece-token svg {
  max-width: 100%;
  max-height: 66px;
  pointer-events: none;
}

.piece-token span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.piece-token.is-used {
  opacity: 0.34;
  cursor: not-allowed;
}

.piece-token.is-selected {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.panel-spacer {
  flex: 1 0 18px;
}

.advanced-panel {
  margin-bottom: 16px;
  border-top: 1px solid var(--panel-line);
  border-bottom: 1px solid var(--panel-line);
}

.advanced-panel summary {
  padding: 13px 0;
  cursor: pointer;
  font-weight: 800;
}

.advanced-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 10px;
  padding-bottom: 14px;
}

.advanced-fields .field-label {
  margin: 0;
  align-self: center;
}

.checkbox-control {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.action-grid button:first-child {
  border-color: var(--accent);
  color: var(--accent);
}

.status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.preview-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  height: 100vh;
  padding: 18px;
  overflow: auto;
}

.preview-column + .preview-column {
  border-left: 1px solid #d9dde2;
}

.preview-column h2 {
  flex: 0 0 auto;
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.canvas-frame {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

.card-canvas {
  width: min(100%, calc((100vh - 78px) * 0.707));
  height: auto;
  max-height: calc(100vh - 78px);
  background: #fff;
  box-shadow: 0 16px 38px rgba(31, 38, 46, 0.18);
}

.interactive-canvas {
  cursor: crosshair;
}

@media (max-width: 980px) {
  .app-shell {
    min-width: 0;
    grid-template-columns: 1fr;
    height: auto;
  }

  .control-panel,
  .preview-column {
    height: auto;
    min-height: 100vh;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--panel-line);
  }
}
