:root {
    color-scheme: light;
    --text: #30383d;
    --page-bg: #f5f5f3;
    --surface: #ffffff;
    --surface-soft: #f7f7f5;
    --text-muted: #70777b;
    --border: #d9dddf;
    --border-strong: #c5cbcd;
    --accent: #39758c;
    --accent-hover: #2e5e70;
    --accent-soft: #eaf1f2;
    --danger: #e74c3c;
    --ui-font: "游明朝", YuMincho, "Hiragino Mincho ProN", "ヒラギノ明朝 ProN", "HG明朝E", "ＭＳ Ｐ明朝", "MS PMincho", "MS 明朝", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--page-bg);
    font-family: var(--ui-font);
}

header {
    display: flex;
    align-items: center;
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 14px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(28, 52, 84, 0.035);
}

h1 {
    margin: 0;
    color: #193653;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

main {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 16px;
}

button,
input,
select,
textarea {
    font-family: var(--ui-font);
}

button {
    width: auto;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    margin: 0;
    background: whitesmoke;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: -3px 3px 8px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    font-size: 15px;
    font-weight: 400;
    letter-spacing: -0.03em;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        color 0.2s ease,
        background-color 0.2s ease,
        border-color 0.2s ease;
}

button:hover {
    background: #f2f2ef;
    border-color: #c9cecf;
    box-shadow: -4px 4px 10px rgba(0, 0, 0, 0.16);
}

button:active {
    transform: translate(-2px, 2px);
    box-shadow: -1px 1px 2px rgba(0, 0, 0, 0.15);
}

button:disabled {
    opacity: 0.35;
    cursor: default;
    box-shadow: none;
    transform: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(40, 120, 208, 0.25);
    outline-offset: 2px;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.tool-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    flex: 1;
    gap: 8px;
}

.tool {
    min-width: 0;
    white-space: nowrap;
}

.tool.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: -3px 3px 8px rgba(57, 117, 140, 0.2);
}

.tool.active:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.history-buttons {
    display: flex;
    flex-shrink: 0;
    gap: 7px;
}

.history-buttons button {
    width: 44px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    font-size: 21px;
    border-radius: 8px;
}

.settings {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(28, 52, 84, 0.035);
}

.setting-group {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    font-size: 13px;
}

.setting-group label {
    color: var(--text);
    font-weight: 650;
    white-space: nowrap;
}

.setting-group span {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
}

.setting-group input[type="number"] {
    width: 65px;
    min-height: 34px;
    padding: 5px 7px;
    color: var(--text);
    background: var(--surface-soft);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: 15px;
    text-align: center;
}

.setting-group input[type="color"] {
    width: 39px;
    height: 34px;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    cursor: pointer;
}

.apply-btn {
    min-height: 36px;
    padding: 8px 16px;
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    font-size: 14px;
    box-shadow: -3px 3px 7px rgba(57, 117, 140, 0.2);
}

.apply-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.zoom-section {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 4px 12px;
    color: var(--text);
    font-size: 13px;
}

.zoom-section label {
    font-weight: 650;
    white-space: nowrap;
}

.zoom-section input[type="range"] {
    flex: 1;
    min-width: 50px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

#zoomValue {
    width: 48px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: right;
}

.status {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--accent-soft);
    border: 1px solid #d9e5e8;
    border-radius: 7px;
    color: var(--accent-hover);
    font-size: 13px;
    line-height: 1.5;
}

.canvas-section {
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(28, 52, 84, 0.035);
}

#canvasViewport {
    width: 100%;
    max-height: 65vh;
    overflow: auto;
    padding: 12px;
    background: rgb(60, 59, 59);
    border: 1px solid #444444;
    border-radius: 8px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

#dotCanvas {
    display: block;
    max-width: none;
    flex-shrink: 0;
    margin: 0 auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#canvasViewport::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#canvasViewport::-webkit-scrollbar-track {
    background: #333333;
    border-radius: 8px;
}

#canvasViewport::-webkit-scrollbar-thumb {
    background: #777777;
    border-radius: 8px;
}

#canvasViewport::-webkit-scrollbar-thumb:hover {
    background: #999999;
}

@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    header {
        padding: 13px 16px;
    }

    h1 {
        font-size: 19px;
    }

    main {
        padding: 12px;
    }

    .toolbar {
        gap: 7px;
    }

    .tool-buttons {
        gap: 5px;
    }

    .tool {
        padding: 9px 5px;
        font-size: 13px;
    }

    .history-buttons {
        gap: 5px;
    }

    .history-buttons button {
        width: 39px;
        height: 40px;
        min-height: 40px;
        font-size: 19px;
    }

    .settings {
        gap: 10px;
        padding: 11px;
    }

    .setting-group {
        gap: 5px;
    }

    .setting-group input[type="number"] {
        width: 58px;
    }

    .apply-btn {
        padding: 8px 12px;
    }

    .canvas-section {
        padding: 8px;
    }

    #canvasViewport {
        max-height: 62vh;
        padding: 9px;
    }
}

@media (max-width: 380px) {
    header {
        padding: 11px 13px;
    }

    main {
        padding: 9px;
    }

    h1 {
        font-size: 18px;
    }

    .toolbar {
        gap: 5px;
    }

    .tool {
        font-size: 12px;
        padding: 9px 3px;
    }

    .history-buttons button {
        width: 35px;
    }

    .settings {
        gap: 8px;
        padding: 9px;
    }

    .setting-group {
        font-size: 12px;
    }

    .setting-group input[type="number"] {
        width: 53px;
        font-size: 14px;
    }

    .apply-btn {
        font-size: 13px;
        padding: 7px 9px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}