:root {
  color-scheme: light;
  --bg: #f4efe6;
  --panel: rgba(255, 252, 247, 0.92);
  --panel-border: #d7cdb8;
  --ink: #2a2419;
  --muted: #6f6757;
  --accent: #1f8f6a;
  --shadow: 0 18px 40px rgba(65, 48, 18, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 220, 163, 0.6), transparent 34%),
    linear-gradient(135deg, #f3ebdb 0%, #efe4d1 45%, #eadfc8 100%);
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

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

.mobile-unsupported {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #6a6a6a;
  color: #ffffff;
  text-align: center;
}

.mobile-unsupported p {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  line-height: 1.5;
}

.topbar,
.statusbar,
.panel,
.canvas-container {
  backdrop-filter: blur(12px);
}

.topbar {
  display: grid;
  gap: 12px;
  padding: 14px 16px 12px;
  background: linear-gradient(180deg, rgba(255, 249, 240, 0.94), rgba(255, 247, 236, 0.78));
  border-bottom: 1px solid rgba(120, 96, 53, 0.18);
}

.brand-row,
.toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.app-title {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(1.1rem, 1.6vw, 1.45rem);
  letter-spacing: 0.03em;
}

.app-title-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex: 0 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
}

.language-select,
.toolbar-row button,
.control-block select,
.file-button,
.mode-button,
.sidebar-action-button,
.sidebar-save-button,
.eraser-type-button {
  min-height: 34px;
  border-radius: 12px;
  border: 1px solid rgba(36, 33, 26, 0.16);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 6px 20px rgba(65, 48, 18, 0.08);
  font-size: 0.84rem;
}

.language-select,
.control-block select {
  padding: 0 12px;
}

.toolbar-row button,
.file-button,
.mode-button,
.sidebar-action-button,
.sidebar-save-button,
.eraser-type-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  cursor: pointer;
}

.file-button {
  background: linear-gradient(135deg, #2aa96f, #187a4d);
  color: #fff;
  border-color: rgba(15, 93, 58, 0.45);
}

.file-button input {
  display: none;
}

.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 248px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.sidebar {
  display: grid;
  gap: 10px;
  align-content: start;
}

.left-sidebar .panel {
  gap: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.compact-panel {
  padding: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.control-block {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.86rem;
}

.control-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.control-block:last-child {
  margin-bottom: 0;
}

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

.inline-label {
  color: var(--ink);
  font-weight: 600;
}

.control-heading strong {
  font-size: 1.2em;
  font-weight: 700;
  color: var(--ink);
}

.mode-button,
.sidebar-action-button,
.sidebar-save-button,
.eraser-type-button {
  width: 100%;
}

.scope-toggle-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.scope-toggle-button {
  min-height: 34px;
  border-radius: 12px;
  border: 1px solid rgba(36, 33, 26, 0.16);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 6px 20px rgba(65, 48, 18, 0.08);
  cursor: pointer;
}

.scope-toggle-button.is-active {
  background: linear-gradient(135deg, var(--accent), #4dbb8c);
  color: #fff;
  border-color: transparent;
}

.checkerboard-theme-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.checkerboard-theme-button {
  position: relative;
  width: 100%;
  max-width: 52px;
  aspect-ratio: 0.82;
  border-radius: 11px;
  border: 2px solid rgba(36, 33, 26, 0.12);
  box-shadow: 0 6px 20px rgba(65, 48, 18, 0.08);
  cursor: pointer;
  overflow: hidden;
  justify-self: center;
}

.checkerboard-theme-button::before {
  content: "";
  position: absolute;
  inset: 0;
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px, 8px 0, 0 8px;
}

.checkerboard-theme-button[data-checkerboard-theme="light"]::before {
  background-image:
    linear-gradient(45deg, #ffffff 25%, transparent 25%),
    linear-gradient(45deg, #ffffff 25%, transparent 25%),
    linear-gradient(45deg, #dde2e6 25%, transparent 25%),
    linear-gradient(45deg, #dde2e6 25%, transparent 25%);
  background-color: #dde2e6;
}

.checkerboard-theme-button[data-checkerboard-theme="mid"]::before {
  background-image:
    linear-gradient(45deg, #7f7f7f 25%, transparent 25%),
    linear-gradient(45deg, #7f7f7f 25%, transparent 25%),
    linear-gradient(45deg, #6a6a6a 25%, transparent 25%),
    linear-gradient(45deg, #6a6a6a 25%, transparent 25%);
  background-color: #6a6a6a;
}

.checkerboard-theme-button[data-checkerboard-theme="dark"]::before {
  background-image:
    linear-gradient(45deg, #444444 25%, transparent 25%),
    linear-gradient(45deg, #444444 25%, transparent 25%),
    linear-gradient(45deg, #353535 25%, transparent 25%),
    linear-gradient(45deg, #353535 25%, transparent 25%);
  background-color: #353535;
}

.checkerboard-theme-button.is-active {
  border-color: rgba(31, 143, 106, 0.9);
  box-shadow: 0 0 0 3px rgba(31, 143, 106, 0.18), 0 10px 24px rgba(65, 48, 18, 0.12);
}

.mode-button.is-active,
.sidebar-action-button.is-active {
  background: linear-gradient(135deg, var(--accent), #4dbb8c);
  color: #fff;
  border-color: transparent;
}

.crop-mode-button {
  background: linear-gradient(135deg, #f3ae35, #df7b20);
  border-color: rgba(176, 104, 25, 0.34);
  color: #ffffff;
}

.crop-mode-button.is-active {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 243, 236, 0.94));
  color: #8a5312;
  border-color: rgba(176, 104, 25, 0.18);
}

.sidebar-save-button {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 243, 236, 0.94));
  color: #6d6254;
}

.sidebar-save-button.is-crop-active {
  background: linear-gradient(135deg, #f3ae35, #df7b20);
  color: #ffffff;
  border-color: rgba(176, 104, 25, 0.34);
}

.workspace {
  min-width: 0;
  min-height: 0;
}

.workspace-stack {
  display: grid;
  gap: 10px;
  min-height: 0;
}

.canvas-container {
  position: relative;
  width: 100%;
  height: min(72vh, calc(100vh - 220px));
  min-height: 430px;
  overflow: scroll;
  scrollbar-gutter: stable both-edges;
  border-radius: 28px;
  border: 1px solid rgba(93, 78, 46, 0.18);
  background: linear-gradient(180deg, rgba(255, 252, 246, 0.8), rgba(243, 235, 220, 0.84));
  box-shadow: var(--shadow);
}

.canvas-stage {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.checkerboard-layer,
.image-layer,
.overlay-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.image-layer,
.overlay-layer {
  touch-action: none;
}

.overlay-layer {
  z-index: 3;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1rem;
  pointer-events: none;
  z-index: 4;
  text-align: center;
}

.empty-state span,
.drop-overlay span {
  display: block;
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  font-weight: 700;
  letter-spacing: 0.03em;
}

.drop-overlay {
  position: absolute;
  inset: 18px;
  z-index: 6;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(31, 143, 106, 0.7);
  border-radius: 24px;
  background: rgba(255, 252, 247, 0.82);
  color: var(--ink);
  pointer-events: none;
  text-align: center;
}

.canvas-container.is-drop-target {
  border-color: rgba(31, 143, 106, 0.45);
  box-shadow: 0 0 0 4px rgba(31, 143, 106, 0.14), var(--shadow);
}

.crop-hud {
  position: absolute;
  top: 14px;
  right: 34px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(25, 23, 20, 0.78);
  color: #fff6e6;
  font-size: 0.82rem;
}

.camera-button {
  min-width: 68px;
  height: 38px;
  border: 0;
  padding: 0 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #d84b45, #a61f2d);
  color: #fff;
  cursor: pointer;
}

.hint-list {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
  line-height: 1.45;
}

.hidden {
  display: none;
}

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px 14px;
  color: var(--muted);
  font-size: 0.78rem;
}

.workspace-statusbar {
  padding: 0 2px 2px;
}

.corner-logo-link {
  position: fixed;
  right: 18px;
  bottom: 16px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(11vw, 94px);
  opacity: 0.94;
  transition: transform 120ms ease, opacity 120ms ease;
}

.corner-logo-link:hover {
  opacity: 1;
  transform: translateY(-1px);
}

.corner-logo-image {
  display: block;
  width: 100%;
  height: auto;
}

.statusbar span {
  background: rgba(255, 249, 240, 0.8);
  border: 1px solid rgba(120, 96, 53, 0.16);
  border-radius: 999px;
  padding: 6px 10px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 220px minmax(0, 1fr) 220px;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .canvas-container {
    height: 58vh;
    min-height: 360px;
  }

  .corner-logo-link {
    right: 12px;
    bottom: 12px;
    max-width: min(16vw, 66px);
  }
}
