:root {
  --bg: #f5f7f6;
  --bg-alt: #ecf0ee;
  --panel: #fafbfa;
  --text: #1a2c24;
  --muted: #6b7b73;
  --primary: #1f8f63;
  --primary-strong: #156647;
  --accent: #f2b950;
  --border: #dfe7e2;
  --shadow: 0 2px 8px rgba(24, 52, 40, 0.06);
  --shadow-hover: 0 4px 12px rgba(24, 52, 40, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-alt) 100%);
}

.background-pattern {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(
      rgba(16, 46, 34, 0.03) 1px,
      transparent 1px
    ),
    linear-gradient(90deg, rgba(16, 46, 34, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1400px, 94vw);
  margin: 2rem auto;
  display: grid;
  gap: 0.85rem;
}

.topbar,
.status-bar,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}

.topbar:hover,
.status-bar:hover,
.panel:hover {
  box-shadow: var(--shadow-hover);
}

.topbar {
  padding: 1.1rem 1.35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.title-wrap h1 {
  margin: 0;
  font-size: clamp(1.25rem, 1.8vw, 1.8rem);
  letter-spacing: 0.01em;
}

.title-wrap p {
  margin: 0.15rem 0 0;
  color: var(--muted);
}

.creator-line {
  margin: 0.2rem 0 0;
}

.creator-link {
  color: var(--primary-strong);
  font-size: 0.9rem;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.creator-link:hover,
.creator-link:focus-visible {
  color: var(--primary);
  border-bottom-color: currentColor;
}

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

.controls-inline select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.35rem 0.6rem;
  background: #fff;
  font: inherit;
  color: inherit;
}

.status-bar {
  padding: 0.65rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.status-toggles {
  display: inline-flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.badge.loading {
  background: #fff4da;
  color: #865a00;
}

.badge.ready {
  background: #d7f4e8;
  color: #16543a;
}

.badge.error {
  background: #ffdede;
  color: #7a1010;
}

.autosync-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.main-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 0.85rem;
}

.panel {
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.2rem 0.2rem 0.7rem;
}

.panel-header h2,
.output-header h3 {
  margin: 0;
  font-size: 1rem;
}

.btn-row {
  display: inline-flex;
  gap: 0.45rem;
}

.btn {
  border: none;
  background: #e8f0ed;
  color: #1a2c24;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: #dce8e2;
}

.btn:active:not(:disabled) {
  background: #cfe1da;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-strong);
}

.btn-primary:active:not(:disabled) {
  background: #105037;
}

.btn-ghost {
  background: #f5f7f6;
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: #eff2f0;
}

.blockly-host {
  flex: 1;
  min-height: 540px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.code-editor {
  width: 100%;
  flex: 1;
  resize: vertical;
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
  font-size: 0.95rem;
  line-height: 1.45;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  color: #1d2e25;
  background: #f8fbf9;
}

.output-wrap {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.4rem;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.output {
  margin: 0;
  min-height: 150px;
  max-height: 230px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
  background: #f4faf6;
  color: #1f2d27;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.88rem;
  line-height: 1.5;
}

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

  .panel {
    min-height: 58vh;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: 96vw;
    margin: 1rem auto;
  }

  .topbar,
  .status-bar,
  .panel {
    border-radius: 13px;
  }

  .topbar,
  .status-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .status-toggles {
    gap: 0.6rem;
  }

  .btn-row {
    flex-wrap: wrap;
  }
}
