:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #10243e;
  --accent: #007a5e;
  --danger: #b42318;
  --muted: #6a7a8b;
  --border: #d8e1ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top right, #eaf8f4, var(--bg));
  color: var(--text);
}

h1,
h2 {
  margin: 0 0 12px 0;
}

p {
  margin: 0;
  color: var(--muted);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-bottom: 16px;
}

body.modal-open {
  overflow: hidden;
}

.modal-card {
  width: min(520px, calc(100% - 32px));
  margin: auto;
  border: none;
  outline: none;
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
}

.modal-card[open] {
  display: block;
}

.modal-card::backdrop {
  background: rgba(16, 36, 62, 0.45);
}

.modal-card > section {
  width: min(520px, 100%);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(10, 20, 40, 0.2);
  padding: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 18px rgba(10, 20, 40, 0.06);
}

.stack {
  display: grid;
  gap: 10px;
}

.hidden {
  display: none;
}

.builder-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 6px;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.button-ghost {
  background: #e7f0ed;
  color: var(--text);
  border: 1px solid var(--border);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-admin {
  background: #d4e6ff;
  color: #0f4c8a;
}

.badge-caster {
  background: #e2f4ec;
  color: #1a6b3c;
}

.auth-wrap {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(420px, 96vw);
}

.auth-error {
  color: var(--danger);
  margin: 6px 0 12px;
}

.layout-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  border: 1px dashed #9ab0c9;
  background:
    linear-gradient(to right, rgba(154, 176, 201, 0.2) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(154, 176, 201, 0.2) 1px, transparent 1px),
    #f9fcff;
  background-size: 6% 6%;
  overflow: hidden;
}

.canvas-widget {
  position: absolute;
  border: 1px solid #1d4f83;
  background: rgba(15, 99, 178, 0.16);
  border-radius: 10px;
  padding: 8px;
  min-width: 80px;
  min-height: 60px;
  user-select: none;
  touch-action: none;
}

.canvas-widget-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.canvas-widget-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.resize-handle {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 12px;
  height: 12px;
  border-right: 2px solid #0b3a66;
  border-bottom: 2px solid #0b3a66;
  cursor: se-resize;
}

.top-gap {
  margin-top: 14px;
}

.upload-status {
  display: block;
  font-size: 0.82rem;
  color: #5a8fc5;
  margin: 4px 0 6px;
}

.upload-preview {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.04);
  margin-top: 4px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

input,
textarea,
select,
button {
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  padding: 10px;
}

textarea {
  width: 100%;
  font-family: Consolas, monospace;
}

button,
.button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  padding: 10px 14px;
  border-radius: 8px;
}

button:hover,
.button:hover {
  filter: brightness(0.95);
}

.small {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.danger {
  background: var(--danger);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}

.inline {
  display: inline;
}

ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.layout-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 12px 0;
  border-radius: 10px;
  border: 1px dashed #9ab0c9;
  background:
    linear-gradient(to right, rgba(154, 176, 201, 0.2) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(154, 176, 201, 0.2) 1px, transparent 1px),
    #f9fcff;
  background-size: 6% 6%;
  overflow: hidden;
}

.layout-preview-widget {
  position: absolute;
  border: 1px solid #1d4f83;
  background: rgba(15, 99, 178, 0.16);
  border-radius: 8px;
  padding: 6px;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
}

.layout-preview-widget span {
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.layout-preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.todo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

@media (max-width: 720px) {
  body {
    padding: 12px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
