:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-surface-raised: #f0f1f4;
  --color-border: #e0e2e7;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;
  --color-accent: #6366f1;
  --color-accent-hover: #4f46e5;
  --color-danger: #ef4444;
  --radius: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
}

button {
  font-family: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

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

.app-header .log img {
  height: 40px;
  width: auto;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

.header-titles {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.header-tagline {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bmc-button {
  height: 40px;
}

.lang-switcher select {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--color-text);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
}

.app-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}

.editor-panel,
.preview-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  width: 100%;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

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

.toolbar label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.toolbar input[type="number"] {
  width: 3.5rem;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
}

.toolbar button {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.toolbar button:not(:disabled):hover {
  border-color: var(--color-accent);
}

.toolbar button.danger-btn:not(:disabled):hover {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.format-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.format-option {
  border: none;
  border-radius: 0;
  background: var(--color-surface-raised);
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text);
}

.format-option.is-active {
  background: var(--color-accent);
  color: white;
}

.editor-grid-wrapper {
  margin-bottom: 1rem;
}

.editor-grid {
  position: relative;
  display: grid;
  gap: 4px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 4px;
  aspect-ratio: 16 / 9;
  max-width: 900px;
  margin: 0 auto;
  user-select: none;
  touch-action: none;
}

.grid-cell {
  background: rgba(0, 0, 0, 0.02);
  border: 1px dashed rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.bento-box {
  position: relative;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  font-size: 0.8rem;
  color: rgba(0, 0, 0, 0.75);
  cursor: grab;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.bento-box.is-selected {
  outline: 2px solid var(--color-accent-hover);
  outline-offset: 1px;
}

.bento-box.is-dragging {
  cursor: grabbing;
  opacity: 0.85;
  z-index: 5;
}

.bento-box .box-label {
  pointer-events: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.box-edge {
  position: absolute;
  z-index: 2;
}

.box-edge--right {
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
}

.box-edge--bottom {
  left: 0;
  bottom: -3px;
  height: 6px;
  width: 100%;
  cursor: ns-resize;
}

.box-edge--left {
  top: 0;
  left: -3px;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
}

.box-edge--top {
  left: 0;
  top: -3px;
  height: 6px;
  width: 100%;
  cursor: ns-resize;
}

.selection-ghost {
  background: rgba(99, 102, 241, 0.25);
  border: 1px dashed var(--color-accent-hover);
  border-radius: 4px;
  pointer-events: none;
  z-index: 10;
}

.inspector-panel {
  border-top: 1px solid var(--color-border);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.inspector-panel[hidden] {
  display: none;
}

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

.inspector-panel label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.inspector-panel input[type="text"] {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
}

.area-name-preview {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.area-name-preview code {
  color: var(--color-accent-hover);
}

.color-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.color-field > span {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.color-preset-list {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.color-preset {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-preset.is-active {
  border-color: var(--color-text);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.preview-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.preview-tab {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: var(--radius);
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

.preview-tab.is-active {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.preview-frame-wrapper {
  position: relative;
  display: flex;
  min-height: 480px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: white;
  overflow: auto;
}

.preview-frame {
  display: none;
  flex: 1;
  width: 100%;
  border: none;
}

.preview-frame.is-active {
  display: block;
}

.browser-device-frame {
  display: none;
  flex: 1;
  flex-direction: column;
  min-width: 900px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: white;
}

.browser-device-frame.is-active {
  display: flex;
}

.browser-device-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 0.5rem 0.75rem;
  background: #e5e5e5;
  border-bottom: 1px solid var(--color-border);
}

.browser-device-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.browser-device-dot--red {
  background: #ff5f57;
}

.browser-device-dot--yellow {
  background: #febc2e;
}

.browser-device-dot--green {
  background: #28c840;
}

.preview-frame--desktop {
  display: block;
  flex: 1;
}

.preview-frame--mobile {
  flex: none;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 28px;
}

.mobile-device-frame {
  display: none;
  flex: none;
  width: 390px;
  height: 580px;
  margin: 1.5rem auto;
  padding: 14px;
  background: #1c1c1e;
  border-radius: 40px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.mobile-device-frame.is-active {
  display: flex;
}

.preview-frame--marp {
  display: block;
  transform: scale(0.6);
  transform-origin: top left;
  width: calc(100% / 0.6);
  height: calc(100% / 0.6);
}

.preview-marp {
  display: none;
  flex: 1;
  width: 100%;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
}

.preview-marp.is-active {
  display: flex;
}

.marp-slide {
  width: 90%;
  aspect-ratio: 16 / 9;
  background: white;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  overflow: hidden;
}

.copy-code-btn {
  background: rgba(20, 20, 20, 0.85);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.copy-code-btn.is-copied {
  background: #16a34a;
}

.code-panel {
  margin-top: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-raised);
  overflow: hidden;
}

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

.code-panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.code-tabs {
  display: flex;
  gap: 0.25rem;
}

.code-tab {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}

.code-tab.is-active {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.code-output {
  margin: 0;
  padding: 1rem;
  max-height: 320px;
  overflow: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--color-text);
  white-space: pre;
}
