@font-face {
  font-family: "Ebrima";
  src: url("ebrima.ttf") format("truetype");
  font-weight: 400;
}

@font-face {
  font-family: "Ebrima";
  src: url("EBRIMABD.TTF") format("truetype");
  font-weight: 700;
}

:root {
  color-scheme: light;
  --bg: #f2efe8;
  --surface: #fffaf0;
  --surface-strong: #ffffff;
  --ink: #26221c;
  --muted: #6f6659;
  --line: #d8cdbd;
  --accent: #b65b31;
  --accent-strong: #914523;
  --danger: #9e2f2f;
  --danger-strong: #7c2323;
  --focus: #2f6f87;
  --shadow: 0 18px 45px rgba(38, 34, 28, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family: "Ebrima", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(rgba(242, 239, 232, 0.88), rgba(242, 239, 232, 0.88)),
    url("bg.jpg") center / cover fixed;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 24px;
  width: min(1680px, 100%);
  min-height: 100vh;
  padding: 24px;
  margin: 0 auto;
}

.tool-panel,
.preview-panel {
  min-width: 0;
  background: rgba(255, 250, 240, 0.96);
  border: 1px solid rgba(216, 205, 189, 0.9);
  box-shadow: var(--shadow);
}

.tool-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 8px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  border-radius: 8px;
  overflow: hidden;
}

.panel-header,
.control-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header {
  background: var(--surface-strong);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(1.55rem, 2vw, 2rem);
}

h2 {
  font-size: 1rem;
}

.mode-link {
  display: inline-flex;
  margin-top: 10px;
  color: var(--focus);
  font-weight: 700;
  text-decoration: none;
}

.mode-link:hover {
  text-decoration: underline;
}

.control-form {
  display: flex;
  flex-direction: column;
}

.control-section {
  display: grid;
  gap: 14px;
}

.control-section h2 {
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.field {
  display: grid;
  gap: 6px;
}

label,
.field-label {
  color: var(--ink);
  font-weight: 700;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

output,
.help-block {
  color: var(--muted);
  font-size: 0.86rem;
}

input[type="text"],
input[type="file"],
select {
  width: 100%;
}

input[type="text"],
select {
  min-height: 42px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 6px;
}

input[type="file"] {
  padding: 9px;
  background: #fffdf8;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(47, 111, 135, 0.32);
  outline-offset: 2px;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

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

.palette {
  display: grid;
  grid-template-columns: repeat(4, 44px);
  gap: 8px;
}

.swatch-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 5px;
  place-items: center;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.swatch-button:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 18px rgba(38, 34, 28, 0.12);
  transform: translateY(-1px);
}

.swatch-button img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.swatch-button.wild {
  grid-column: span 2;
  width: 96px;
}

.primary-button,
.danger-button,
.text-button {
  min-height: 40px;
  padding: 9px 13px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.danger-button {
  width: 100%;
  color: #ffffff;
  background: var(--danger);
}

.danger-button:hover {
  background: var(--danger-strong);
}

.text-button {
  min-height: auto;
  padding: 4px 7px;
  color: var(--focus);
  background: transparent;
}

.text-button:hover {
  text-decoration: underline;
}

.stage-wrap {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 18px;
  overflow: auto;
}

.floating-download {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 3;
  box-shadow: 0 10px 24px rgba(38, 34, 28, 0.22);
}

.canvas-hint {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 2;
  max-width: min(360px, calc(100% - 160px));
  padding: 9px 12px;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  background: rgba(38, 34, 28, 0.78);
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
}

.stage-wrap:hover .canvas-hint {
  animation: hint-fade 2.8s ease forwards;
}

@keyframes hint-fade {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }

  15% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  70% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }
}

#portraitCanvas {
  line-height: 0;
}

canvas {
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(38, 34, 28, 0.28);
}

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

  .tool-panel,
  .preview-panel {
    max-height: none;
    min-height: auto;
  }

  .preview-panel {
    max-height: calc(100vh - 28px);
  }
}

@media (max-width: 520px) {
  .panel-header,
  .control-section,
  .stage-wrap {
    padding: 14px;
  }

  .floating-download {
    top: 14px;
    right: 14px;
  }

  .canvas-hint {
    top: 62px;
    max-width: calc(100% - 28px);
  }

  .reward-grid {
    grid-template-columns: 1fr;
  }
}
